WP7 Mango:SystemTrayのカスタマイズ
Windows Phone OS 7.0に比べてWindows Phone OS 7.1になってからSystemTrayのプロパティが増えました。
[7.0]
[7.1]
これを比較すると、、
- BackgroundColor(背景色)
- ForegroundColor(前景色)
- Opacity(透明度)
- ProgressIndicator(インジケータの進捗)
のプロパティが増えています。
ProgressIndicatorはロードしているときやアップデートしているときにその状態を表示するオブジェクトです。使い方はこのようになります。
main.xaml
<phone:PhoneApplicationPage x:Class="SystemTray.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" shell:SystemTray.IsVisible="True" shell:SystemTray.BackgroundColor="Orange" shell:SystemTray.ForegroundColor="Blue" shell:SystemTray.Opacity="0.7"> <shell:SystemTray.ProgressIndicator> <shell:ProgressIndicator Text="Loading..." IsIndeterminate="True" IsVisible="True"> </shell:ProgressIndicator> </shell:SystemTray.ProgressIndicator> ...
shell:SystemTrayのプロパティをセットしています。
背景をLightにしたときのイメージはこのようになります。
ただし上記の定義では値が固定になってしまい、特にProgressIndicatorが出っ放しというのも変なので、動的に変更したい場合は下記のようにします。
main.cs
// Constructor public MainPage() { InitializeComponent(); SystemTray.SetIsVisible(this, true); SystemTray.SetOpacity(this, 0.7); SystemTray.SetBackgroundColor(this, Colors.Orange); SystemTray.SetForegroundColor(this, Colors.Blue); var prog = new ProgressIndicator(); prog.IsVisible = true; prog.IsIndeterminate = true; prog.Text = "Loading..."; SystemTray.SetProgressIndicator(this, prog); }
いろいろアプリケーションを観察してみるとシステムトレイが表示されていない(透過している)アプリが結構あります。Peopleハブやミュージックハブ、サードパーティのアプリケーションでは公式のTwitterクライアントやFacebookクライアントもシステムトレイが表示されていません。
特にテーマを活かさないアプリ(独自に背景などを作っている)の場合にはかえって邪魔になる場合があるので、そのときはシステムトレイの色をそのアプリの色に合わせるかシステムトレイごと消してしまうのがよいと思います。
参考:MSDN Library