我在ListViewItem上显示MenuFlyout时遇到问题。 我搜索了网页,我找到的所有示例几乎相同(在xaml中附加MenuFlyout并在Hold事件中打开它)。
菜单有效,但问题是ListView。 如果我在列表视图项目上按住“鼠标”,则菜单会出现,但如果我不释放“鼠标”,我可以滚动列表视图并显示MenuFlyout。
如何阻止listview在这种情况下滚动?
示例代码: XAML:
<Grid>
<ListView Name="ListView">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Holding="Grid_Holding">
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Delete" />
<MenuFlyoutItem Text="Refresh" />
<MenuFlyoutItem Text="Share" />
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<TextBlock Text="{Binding}" FontSize="24" TextTrimming="CharacterEllipsis" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
C#:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
List<string> strings = new List<string>();
Random rnd = new Random();
for (int i = 0; i < 1000; i++) {
StringBuilder sb = new StringBuilder();
for (int j = 0; j < 30; j++) {
sb.Append((char)rnd.Next(97, 122));
}
strings.Add(sb.ToString());
}
ListView.ItemsSource = strings;
}
private void Grid_Holding(object sender, HoldingRoutedEventArgs e)
{
FrameworkElement senderElement = sender as FrameworkElement;
FlyoutBase flyoutBase = FlyoutBase.GetAttachedFlyout(senderElement);
flyoutBase.ShowAt(senderElement);
e.Handled = true;
}