在其他RightTapped不开枪地铁的ListViewItem ListView控件是否比"无"选择模式 [英] RightTapped not fired on Metro ListViewItem if ListView in other than "None" selection mode

查看:150
本文介绍了在其他RightTapped不开枪地铁的ListViewItem ListView控件是否比"无"选择模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里所描述的问题是几乎相同的:的 http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/542b827a-7c8e-4984-9158-9d8479b2d5b1 但我并不满足于接受的答案那里,觉得必须有一个更好的解决办法...

The issue is practically the same as described here: http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/542b827a-7c8e-4984-9158-9d8479b2d5b1 but I am not satisfied with the answer accepted there and feel that there must be a better solution...

我想实现我的列表视图CLASIC上下文菜单(不是通过AppBar而是通过PopupMenu的),而且工作得很好,但只有当我设置列表视图进入无的SelectionMode。

I am trying to implement a 'clasic' context menu on my list view (not via the AppBar but via PopupMenu) and that works fine, however only if I set the list view into the "None" SelectionMode.

上面的链接正确地解释说,ListViewItem的燕子的权利窃听事件的ListView如果设置为除无选择模式。我怎么能覆盖这个行为,让列表视图项被选中和列表视图仍然激发RightTapped事件,我可以反应呢?

The link above correctly explains that the ListViewItem 'swallows' the right tapped event if ListView set to other than "None" selection mode. How can I override this behavior, so that the list view items gets selected AND the list view still fires the RightTapped event which I can react on?

推荐答案

我相信我通过继承这两个ListView和ListViewItem的类解决了这个问题。

I believe I solved the problem by subclassing both ListView and ListViewItem classes.

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>

通过这个简单的方法MyListView_RightTapped即使selectionMode是设置为'单',处理程序被称为多或扩展。但接下来的问题是这个小的胜利是否会导致应用程序的用户界面的一个很好的设计。我不会试图在这里回答这个问题...

By this simple approach MyListView_RightTapped handler is called even if SelectionMode is set to 'Single', 'Multiple' or 'Extended'. Next question however is whether this small victory leads to a good design of the application UI. I will not try to answer that question here...

这篇关于在其他RightTapped不开枪地铁的ListViewItem ListView控件是否比&QUOT;无&QUOT;选择模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆