我在1.xaml文件中有以下代码:
<DataTemplate x:Key="ShellListItemDataTemplate">
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{ThemeResource SystemControlAcrylicWindowBrush}">
<Grid Margin="10" Width="200" Height="100">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding ShellAddress}" Grid.Row="0" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding CreateTime}" HorizontalAlignment="Center" Grid.Row="1"/>
</Grid>
<!--菜单-->
<Border.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="文件管理" Click="MenuFlyoutItem_Click" Tag="FileManager"/>
<MenuFlyoutItem Text="远程命令" Click="MenuFlyoutItem_Click" Tag="RemoteShell"/>
<MenuFlyoutSeparator/>
<MenuFlyoutItem Text="编辑" Click="MenuFlyoutItem_Click" Tag="Modify"/>
<MenuFlyoutItem Text="删除" Click="MenuFlyoutItem_Click" Tag="Delete"/>
</MenuFlyout>
</Border.ContextFlyout>
</Border>
</DataTemplate>
然后在另一个2.xaml中使用:
<GridView Name="shellList" Margin="5" Grid.Row="1" SelectionMode="Single" IsItemClickEnabled="True" ItemTemplate="{StaticResource ShellListItemDataTemplate}" ItemClick="shellList_ItemClick"/>
在2.cs中有以下函数声明:
private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Menu Click!");
}
为什么菜单无法调用MenuFlyoutItem_Click函数呢?