简体   繁体   中英

WP7 - show hide application bar

In many of the Windows Phone 7 apps, the application bar is hidden by default and when you press and hold down on the screen, the application bar is made visible. As many of the WP7 apps have this behavior, I was wondering, if there was in-built support for this kind of behavior with the ApplicationBar and how do I go about using it?

You can use the GestureService in the toolkit to detect the Hold event.

For example.
If you had this xaml on a page:

<TextBlock TextWrapping="Wrap" Text="lorem ipsum ...">
    <toolkit:GestureService.GestureListener>
        <toolkit:GestureListener Hold="TapAndHold" />
    </toolkit:GestureService.GestureListener>
</TextBlock>

and the following for the event handler:

private void TapAndHold(object sender, GestureEventArgs e)
{
    this.ApplicationBar.IsVisible = !this.ApplicationBar.IsVisible;
}

then holding down any where on the textblock would toggle the display of the ApplicationBar.

If you wanted the toggling if the user tapped and held anywhere on the page then you could attach the gesture listener to the root object of the page. eg

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <toolkit:GestureService.GestureListener>
        <toolkit:GestureListener Hold="TapAndHold" />
    </toolkit:GestureService.GestureListener>

Use the ApplicationBar property of the current page and toggle the IsVisible property accordingly to show/hide the ApplicationBar. The ApplicationBar is handled by the operating system, so the animation for showing and hiding it will be handled for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM