WP7 Study Notes (2): Application bar and landscape support

Source: Internet
Author: User

Application bar

In the process of application development, we often need to use an additional menu bar. In WP7, Microsoft provides us with good support in this aspect-ApplicationBar.

By default, ApplicationBar uses the color of the system theme (white and black), which is changed accordingly when the system theme is changed. The ApplicationBar supports a maximum of four icon buttons and a maximum of five sub-items in the menu bar. When more than nine icons are used, we need to consider whether the design is reasonable. Some icons of WP7 can be used in the icon button. You can also make them if they cannot meet your needs, but pay attention to consistent style.

ApplicationBar can be generated through XAML. When a page is created, a part of the annotated code is automatically generated. Canceling the annotation is the ApplicationBar in XAML. We can modify it as needed.

<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

ApplicationBar does not inherit from frameworkelement, so it does not support binding. To change the font type or font size during runtime, you must use C # code to generate ApplicationBar for control.

ApplicationBar = new ApplicationBar ();
ApplicationBar. isvisible = true;
ApplicationBar. ismenuenabled = true;

Applicationbariconbutton btnadd = new applicationbariconbutton (New uri ("/icons/icons1.png", urikind. relativeorabsolute ));
Btnadd. Text = "add ";
ApplicationBar. Buttons. Add (btnadd );

Applicationbarmenuitem itemadd = new applicationbarmenuitem ();
ApplicationBar. menuitems. Add (itemadd );

 

Horizontal and vertical screen support

The WP7 application can develop horizontal or vertical screens, but cannot force change the screen direction through code.

During the development process, we can change supportedorientations to change the screen support.

    Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"

Supportedorientations supports portraitorlandscape, landscape, and portrait. The default value is portrait. You can change the initial orientation of the screen through orientation.

When the screen direction changes, the program layout often does not meet the original design intention. We need to use the orientationchanged event for corresponding processing.

OrientationChanged += new EventHandler<OrientationChangedEventArgs>(SecondPage_OrientationChanged);

Hiding system pallets

In the development process, we may need to maximize our program, which requires that we can hide the system tray, and we can change it through code.

this.SetValue(SystemTray.IsVisibleProperty, !(bool)this.GetValue(SystemTray.IsVisibleProperty));

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.