桌面应用程序的保持事件未触发 [英] Holding event for desktop app not firing

查看:46
本文介绍了桌面应用程序的保持事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的通用 Windows 应用中,我订阅了我的 ListViewItem DataTemplat 中的 Holding 事件e:

In my Universal Windows App, I am subscribing to the Holding event in my ListViewItem DataTemplate:

        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid Holding="ListViewItem_Holding">
                    <FlyoutBase.AttachedFlyout>
                        <MenuFlyout Placement="Right">
                            <!-- using the Click event -->
                            <MenuFlyoutItem Text="delete" Click="DeleteProductClick" />

                            <MenuFlyoutItem Text="edit" />
                        </MenuFlyout>
                    </FlyoutBase.AttachedFlyout>
                    <TextBlock Text="{Binding Name}" />
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>

使用 Visual Studio 模拟器和触摸模式一切正常,但我找不到使用鼠标调用上下文菜单的方法.我是否必须使用 GestureRecognizer 才能使上下文菜单适用于桌面应用程序(而不是平板电脑版本)?

All works well using the Visual Studio Simulator and touch mode, but I cannot find a way to invoke the context menu using my mouse. Do I have to use a GestureRecognizer to get the context menu to work for the desktop application (as opposed to the tablet version)?

推荐答案

我会使用 RightTapped 事件,以便在用户按住基于触摸的设备中的项目时以及当用户在基于鼠标的设备中使用鼠标右键单击时显示上下文菜单设备:

I would use the RightTapped event instead so that the context menu shows up when user holds on an item in a touch based device and also when user right clicks with a mouse in a mouse based device:

<Page.Resources>
   <MenuFlyout x:Key="flyout">
     ...
   </MenuFlyout>

</Page.Resources>
...

<ListView ....>
  <ListView.ItemTemplate>
     <DataTemplate>
       <Grid RightTapped="grid_RightTapped">
            ...
       </Grid>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

然后在后面的代码中处理事件:

Then handle the event in code behind:

private void grid_RightTapped(object sender, RightTappedRoutedEventArgs e) { 
   this.flyout.ShowAt(this, e.GetPosition(this));
   e.Handled = true;
}

如您所见,我使用了共享弹出按钮,您可以按照自己的方式进行.

As you see I've used a shared flyout, you can go with your own way.

这篇关于桌面应用程序的保持事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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