问题描述
在许多 Windows Phone 7 应用程序中,应用程序栏在默认情况下是隐藏的,当您按住屏幕时,应用程序栏将变为可见.由于许多 WP7 应用程序都有这种行为,我想知道,ApplicationBar 是否有对这种行为的内置支持,我该如何使用它?
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?
推荐答案
您可以使用 toolkit 来检测 Hold
事件.
You can use the GestureService in the toolkit to detect the Hold
event.
例如.
如果页面上有这个 xaml:
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;
}
然后按住文本块上的任何位置将切换 ApplicationBar 的显示.
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. e.g.
<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>
这篇关于WP7 - 显示隐藏应用程序栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!