2011-01-14 91 views
3

在許多Windows Phone 7應用程序中,應用程序欄默認爲隱藏狀態,當您按住屏幕上的按鈕時,應用程序欄將變爲可見。由於許多WP7應用程序都有這種行爲,所以我想知道,是否有與ApplicationBar的這種行爲的內置支持,以及如何使用它?WP7 - show hide應用程序欄

+0

可能重複的[Windows Phone 7的隱藏應用程序欄(http://stackoverflow.com/questions/4116311/windows-phone-7-hiding-the-application-bar) – 2011-01-14 06:13:28

回答

6

您可以使用toolkit中的手勢服務來檢測Hold事件。

例如。
如果你有一個頁面上此XAML:

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

和事件處理程序如下:

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

然後按住該文本塊的任何地方將切換應用程序任務欄的顯示。

如果您希望切換用戶在頁面上的任意位置輕敲並保持,則可以將手勢監聽器附加到頁面的根對象。例如

<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> 
1

使用當前頁面的ApplicationBar屬性並相應地切換IsVisible屬性以顯示/隱藏ApplicationBar。 ApplicationBar由操作系統處理,因此用於顯示和隱藏它的動畫將爲您處理。