Windows 10 UWP – Template 10 Mobile Status Bar

Windows-Dev

Template 10 is a set of Visual Studio project templates for Windows 10 XAML / C# apps.

In my previous post I set the app theme to Light and found that the status bar was completely white on Windows 10 Mobile. The status icons were no longer visible.

Before we can make changes to the status bar we first need to add Windows Mobile Extensions for the UWP  to our references:

In the Solution Explorer right click on References and then click Add Reference. In the left pane select Universal Windows and then Extensions from the drop down menu. In the right hand pane select Windows Mobile Extensions for the UWP and click OK.

Now we can customize the status bar by adding the highlighted code to App.xaml.cs.

public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
        {
            // TODO: add your long-running task here
            await NavigationService.NavigateAsync(typeof(Views.MainPage));
           
            //Set StatusBar background and foreground colors
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))

            {
                var statusBar = StatusBar.GetForCurrentView();
                if (statusBar != null)
                {
                    statusBar.BackgroundOpacity = 1;
                    statusBar.BackgroundColor = Colors.Orange;
                    statusBar.ForegroundColor = Colors.White;
                }

Next just add the required using statements as prompted by Visual Studio.

As you can see I set the background color to orange and the text to white:

uwp-status-bar

Sources:

View story at Medium.com

https://stenobot.wordpress.com/2015/07/08/uwp-app-development-styling-the-mobile-status-bar/

https://blogs.msdn.microsoft.com/gianlucb/2015/10/08/uwp-windows-10-app-titlebar-and-status-bar-customization/

Windows 10 UWP – Setting a Light Theme in Template 10

Windows-Dev

Template 10 is a set of Visual Studio project templates for Window 10 XAML / C# apps. By default Template 10 uses the Dark theme.

If you need to switch the Light theme you can add the following code to App.xaml in <common:Bootstrapper:

RequestedTheme="Light"

To see this change in the designer, save changes and restart Visual Studio.

Windows Runtime – C# Send EMail from App

Windows-Dev

I’m working on my About page for a Windows Phone Runtime app and needed to be able to send an email for feedback or support issues.

Below is the code for my event handler in the code behind (AboutPage.cs):

        async private void Image_Email(object sender, TappedRoutedEventArgs e)
        {
            //Define email address to send to
            EmailRecipient sendTo = new EmailRecipient()
            {
                Address = "mail@domain.com"
            };

            //New email and define email subject
            EmailMessage mail = new EmailMessage();
            mail.Subject = "Linux Essentials - Feedback";

            //Add addressee to email
            mail.To.Add(sendTo);

            //Open share contact with email only
            await EmailManager.ShowComposeNewEmailAsync(mail);
        }

The XAML on my About page is simply an image with the Tapped event:

      <Image Source="Assets/Images/Mail.png"
             Height="64"
             Width="64"
             Margin="0,0,22,0"
             Tapped="Image_Email"/>

When defining a new email you can also specify the mail body text:

mail.Body = "this is the Body";

Source: http://dotnet.dzone.com/articles/how-send-mail-your-windows

Windows Runtime – C# Launch Hyperlink

Windows-Dev

I’m working on my About page for a Windows Phone Runtime app and needed to open a hyperlink in my code behind (AboutPage.cs).

Below is the code for my Tapped event handler:

        private void Image_Wordpress(object sender, TappedRoutedEventArgs e)
        {
            Launcher.LaunchUriAsync(new Uri("https://pricklytech.wordpress.com/"));
        }

The XAML on my About page is simply an image with the Tapped event:

      <Image Source="Assets/Images/Wordpress.png"
             Height="64"
             Width="64"
             Tapped="Image_Wordpress"/>

Source: http://stackoverflow.com/questions/12501174/opening-a-url-in-the-default-browser-in-a-windows-8-desktop-application