Zhang Happy UWP development Note: Phone status bar StatusBar

Source: Internet
Author: User

UWP about the app title bar titlebar more articles, but the introduction of StatusBar but not a few, here casually write. Status bar StatusBar usage is relatively simple, take a little thought to design a little bit, the application will be a very good embellishment.

To illustrate, when the application runs on the PC we call TitleBar, when running on Mobile we call StatusBar, this is two different things.

  

Before using StatusBar, you need to add the Windows Mobile Extensions for the UWP in the project reference and reference The Windows.UI.ViewManagement namespace.

There are three methods in the StatusBar class. A static method Getforcurrentview () , respectively, for obtaining the current StatusBar instance. Two async methods Hideasync () and Showasync () , respectively, are used to display and hide StatusBar.

Five attributes. Two nullable color types, backgroundcolor and foregroundcolor , are used to set the background and foreground colors, respectively. A double of type backgroundopacity , with a value range of 0-1, used to set StatusBar transparency. Two read-only properties that return the occludedrect of the rect rectangle and the progressindicator of the Statusbarprogressindicator type, The Progressindicator property is not well understood.

Two of events. hiding and Showing .

A simple example is given below (Github:https://github.com/zhanggaoxing/uwp-demo/tree/master/statusbardemo)

  

  MainPage.xaml

<Pagex:class= "Statusbardemo.mainpage"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local= "Using:statusbardemo"xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"XMLNS:MC= "http://schemas.openxmlformats.org/markup-compatibility/2006"mc:ignorable= "D">    <GridBackground="{ThemeResource Applicationpagebackgroundthemebrush}">        <grid.rowdefinitions>            <RowDefinitionHeight= "Auto" />            <RowDefinitionHeight= "Auto" />            <RowDefinitionHeight= "Auto" />            <RowDefinitionHeight="*" />        </grid.rowdefinitions>        <TextBlockText= "Status Bar Demo"FontSize= "+"Margin= " the" />        <StackPanelGrid.Row= "1"Margin= " the">            <TextBlockText= "Show or hide status bar" />            <RadioButtonName= "Show"GroupName= "Showorhide"IsChecked= "True"Checked= "radiobutton_checked">Show</RadioButton>            <RadioButtonName= "Hide"GroupName= "Showorhide"Checked= "radiobutton_checked">Hide</RadioButton>        </StackPanel>        <StackPanelGrid.Row= "2"Margin= " the">            <TextBlockText= "Change status bar background color" />            <RadioButtonName= "Black"GroupName= "Color"IsChecked= "True"Checked= "color_checked">Black</RadioButton>            <RadioButtonName= "White"GroupName= "Color"Checked= "color_checked">White</RadioButton>            <RadioButtonName= "Accent"GroupName= "Color"Checked= "color_checked">System Accent Color</RadioButton>        </StackPanel>        <StackPanelGrid.Row= "3"Margin= " the">            <TextBlockText= "Change status bar background opacity" />            <SliderName= "Opacity"Minimum= "0"Maximum= "Ten"Value= "Ten"valuechanged= "Opacity_valuechanged" />        </StackPanel>    </Grid></Page>

MainPage.xaml.cs

usingSystem;usingWindows.UI.Xaml;usingWindows.UI.Xaml.Controls;usingWindows.UI.ViewManagement;usingWindows.Foundation.Metadata;usingWindows.ui;usingWindows.UI.Xaml.Media;namespacestatusbardemo{ Public Sealed Partial classmainpage:page {StatusBar StatusBar; //Get system Current colorSolidColorBrush Accentcolor = (SolidColorBrush) application.current.resources["Systemcontrolbackgroundaccentbrush"];  PublicMainPage () {//determine if there is StatusBar            if(Apiinformation.istypepresent ("Windows.UI.ViewManagement.StatusBar") ) {StatusBar=Statusbar.getforcurrentview (); }            Else{Application.Current.Exit (); }             This.        InitializeComponent (); }        //Show, Hide        Private Async voidRadiobutton_checked (Objectsender, RoutedEventArgs e) {RadioButton R= Sender asRadioButton; if(R.name = ="Show")            {                awaitStatusbar.showasync (); }            Else            {                awaitStatusbar.hideasync (); }        }        //Color        Private voidColor_checked (Objectsender, RoutedEventArgs e) {RadioButton R= Sender asRadioButton; if(R.name = ="Black") {Statusbar.backgroundcolor=Colors.black; Statusbar.foregroundcolor=Colors.white; }            Else if(R.name = =" White") {Statusbar.backgroundcolor=Colors.white; Statusbar.foregroundcolor=Colors.black; Statusbar.backgroundopacity=1; }            Else{Statusbar.backgroundcolor=Accentcolor.color; Statusbar.foregroundcolor=Colors.black; Statusbar.backgroundopacity=1; }        }        //Transparency        Private voidOpacity_valuechanged (Objectsender, Windows.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e) {statusbar.backgroundopacity= Opacity.value/Ten; }    }}

Zhang Happy UWP development Note: Phone status bar StatusBar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.