如何使用VB / XAML从WP中的appbar图标(如在whatsapp中附加)创建弹出菜单。我尝试使用导航,但无法执行它而不是导航到另一个页面??
答案 0 :(得分:0)
看来,在whatsapp中附加是一个简单的网格,AppBar中的按钮只会改变其可见性。另外,如果附加网格内容可见,则OnBackKeyPress页面设置为e.Cancel = true。
所以XAML看起来像这样:
<Grid x:Name="LayoutRoot"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <!--Header-->
<RowDefinition Height="*" /> <!--Content-->
<RowDefinition Height="Auto" /> <!--Fake popup-->
</Grid.RowDefinitions>
<!-- ... -->
<Grid Grid.Row="2"
x:Name="SomeName"
Visibility="Collapsed">
<!-- Fake popup-->
</Grid>
</Grid>
<强>更新强>
对于您,页面内容应如下所示:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <!--Header-->
<RowDefinition Height="*" /> <!--Content-->
<RowDefinition Height="Auto" /> <!--Fake popup-->
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel"
Grid.Row="0"
Margin="12,17,0,28">
<!--TitlePanel contains the name of the application and page title-->
</StackPanel>
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0">
<!--ContentPanel - place additional content here-->
</Grid>
<Grid Grid.Row="2"
x:Name="SomeName"
Visibility="Collapsed">
<!--Popup-->
</Grid>
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar>
<shell:ApplicationBarIconButton Text="show popup"
IconUri="/icon.png"
Click="ApplicationBarIconButton_Click" />
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
VB.net上的页面代码如下所示:
Partial Public Class MainPage
Inherits PhoneApplicationPage
Public Sub New()
InitializeComponent()
End Sub
' If you want to hide popup when Back key pressed '
Protected Overrides Sub OnBackKeyPress(e As ComponentModel.CancelEventArgs)
If SomeName.Visibility = Windows.Visibility.Visible Then
SomeName.Visibility = Windows.Visibility.Collapsed
e.Cancel = True
End If
MyBase.OnBackKeyPress(e)
End Sub
' Here is popup will appear and hide '
Private Sub ApplicationBarIconButton_Click(sender As Object, e As EventArgs)
If SomeName.Visibility = Windows.Visibility.Visible Then
SomeName.Visibility = Windows.Visibility.Collapsed
Else
SomeName.Visibility = Windows.Visibility.Visible
End If
End Sub
End Class