gpt4 book ai didi

c# - 如果 ListView 不是 "None"选择模式,则 RightTapped 不会在 Metro ListViewItem 上触发

转载 作者:行者123 更新时间:2023-11-30 14:00:33 25 4
gpt4 key购买 nike

问题实际上与此处描述的相同:http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/542b827a-7c8e-4984-9158-9d8479b2d5b1但我对那里接受的答案并不满意,觉得必须有更好的解决方案......

我正在尝试在我的 ListView 上实现一个“经典”上下文菜单(不是通过 AppBar,而是通过 PopupMenu)并且效果很好,但前提是我将 ListView 设置为“无”选择模式。

上面的链接正确地解释了如果 ListView 设置为“无”选择模式以外的其他选择模式,ListViewItem 会“吞噬”右侧的点击事件。我如何覆盖此行为,以便选择 ListView 项并且 ListView 仍会触发我可以对其使用react的 RightTapped 事件?

最佳答案

我相信我通过子类化 ListView 和 ListViewItem 类解决了这个问题。

public class MyListView : ListView
{
protected override DependencyObject GetContainerForItemOverride()
{
return new MyListViewItem();
}
}

public class MyListViewItem : ListViewItem
{
protected override void OnRightTapped(Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
{
base.OnRightTapped(e);
e.Handled = false; // Stop 'swallowing' the event
}
}

<CustomControls:MyListView
x:Name="MyListView"
...
SelectionMode="Single"
RightTapped="MyListView_RightTapped">
</CustomControls:MyListView>

通过这种简单的方法,即使 SelectionMode 设置为“Single”、“Multiple”或“Extended”,MyListView_RightTapped 处理程序也会被调用。然而,下一个问题是这个小胜利是否会导致应用程序 UI 的良好设计。我不会在这里尝试回答这个问题......

关于c# - 如果 ListView 不是 "None"选择模式,则 RightTapped 不会在 Metro ListViewItem 上触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10490709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com