c# – 弹出菜单Windows Phone 8.1暂停Listview
作者:互联网
如何在列表视图中使用项目时如何显示弹出菜单?我试过但是hold方法引用了listview而不是它自己的项目.
解决方法:
您可以订阅Item的Template Holding事件.例如这样:
<ListView.ItemTemplate>
<DataTemplate>
<Grid Holding="Grid_Holding" VerticalAlignment="Stretch">
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="EditButton"
Text="Edit"
Click="EditButton_Click"/>
<MenuFlyoutItem x:Name="DeleteButton"
Text="Delete"
Click="DeleteButton_Click"/>
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<TextBlock Text="{Binding}" VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
在后面的代码中,显示弹出窗口:
private void Grid_Holding(object sender, HoldingRoutedEventArgs e)
{
FrameworkElement senderElement = sender as FrameworkElement;
// If you need the clicked element:
// Item whichOne = senderElement.DataContext as Item;
FlyoutBase flyoutBase = FlyoutBase.GetAttachedFlyout(senderElement);
flyoutBase.ShowAt(senderElement);
}
private async void EditButton_Click(object sender, RoutedEventArgs e)
{
// get the clicked element:
Item datacontext = (e.OriginalSource as FrameworkElement).DataContext as Item;
await new MessageDialog("Edit").ShowAsync();
}
如果您愿意,也可以使用“行为”进行操作.您还可以在Igrali’s blog post找到一些帮助.
标签:c,xaml,windows-phone-8-1 来源: https://codeday.me/bug/20190715/1466493.html