Status Bar (SystemTray) for Silverlight Apps for Windows Phone 8.1?

In my last post, I talked about using the “Status Bar” in Windows Phone 8.1 to make optimal use of our screen space, like the Bing apps do. What I forgot to mention, was the code mentioned in that post applies only to the new Windows Phone 8.1 Universal Apps (i.e., targeting Windows RT).

If you are using Silverlight for Windows Phone 8.1, we will have to use the Microsoft.Phone.Shell.SystemTray class instead.

You could easily set the SystemTray properties in your XAML page like this:

    1: <phone:PhoneApplicationPage
    2:     x:Class="SLApp.MainPage"
    3:     xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
    4:     xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
    5:     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    6:     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    7:     xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
    8:     xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
    9:     mc:Ignorable="d"
   10:     FontFamily="{StaticResource PhoneFontFamilyNormal}"
   11:     FontSize="{StaticResource PhoneFontSizeNormal}"
   12:     Foreground="{StaticResource PhoneForegroundBrush}"
   13:     SupportedOrientations="Portrait" Orientation="Portrait"
   14:     shell:SystemTray.IsVisible="True"
   15:     shell:SystemTray.BackgroundColor="Blue" 
   16:     shell:SystemTray.ForegroundColor="White" 
   17:     shell:SystemTray.Opacity="1" >

And then, in the xaml.cs, you can set the ProgressIndicator like this:

    1: public MainPage()
    2: {
    3:     InitializeComponent();
    4:  
    5:     var prog = new ProgressIndicator { Text = "My app", IsVisible=true, IsIndeterminate=false,Value=0 };
    6:     SystemTray.SetProgressIndicator(this, prog);
    7: }

And we’re done!

To summarize:

Windows Phone 8.1 (RT/Universal App) --> use Windows.UI.ViewManagement.StatusBar

Silverlight app for Windows Phone 8.1 --> use Microsoft.Phone.Shell.SystemTray

 

Thank you, @xuggs for bringing this up! Hope this helps :)

 

Thanks for reading!

Amar

PS: You can follow me on twitter at “_amarnit”, where I share some quick tips/learning at times!