禁用上下文菜单WPF [英] Disabling a context menu WPF

查看:119
本文介绍了禁用上下文菜单WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多控件的WPF表单。一些控件有上下文菜单(一些内置,一些我添加)。我还在视图的基础网格上添加了一个上下文菜单,以捕获没有上下文菜单的任何内容。所有这一切都很好。



现在使用网格上下文菜单,有时我根本不希望它显示(就像我处于编辑模式时)。问题是我对基础网格所做的任何事情上下文菜单也发生在视图中的所有其他上下文菜单中。我只希望它应用于基础Grid的上下文菜单。



如何将其中一个上下文菜单与其他菜单分开?不幸的是,ContextMenuOpening事件并没有告诉我它试图打开哪个上下文菜单。上下文菜单没有打开事件。如果我使用打开它会闪烁。



还有其他任何想法吗?



我是什么尝试过:



包含在上面的问题中。



更多的东西:

* Loaded事件 - 很高兴让它隐藏起来,而不是让它恢复生机。

*可见性属性 - 当我取消编辑模式时,上下文菜单弹出。它需要等待右键单击。

I have a WPF form with many controls. Some of the controls have context menus (some built-in, some I added). I also added a context menu on the base Grid of the view to catch anything that doesn't have a context menu. All this works fine.

Now with the Grid context menu, sometimes I don't want it to display at all (like when I am in edit mode). The problem is whatever I do to the base Grid's context menu also happens to all of the other context menus in the view. I only want it to apply to the base Grid's context menu.

How can I separate the one context menu from all the rest? Unfortunately the ContextMenuOpening event doesn't tell me which context menu it it trying to open. The context menu doesn't have an "Opening" event. If I use "Opened" it flashes.

Any other ideas?

What I have tried:

Included in the problem above.

More things:
*The Loaded event - It is happy to make it hidden, not so much to bring it back to life.
*Visibility property - When I cancel the edit mode, the context menu pops up. It needs to wait for a right-click.

推荐答案

自己解决:



我正在使用Loaded事件中的错误属性。



Solved it myself:

I was using the wrong properties in the Loaded event.

private void appHistory_Loaded(object sender, RoutedEventArgs e)
{
    ContextMenu cm = sender as ContextMenu;
    if (cm != null)
    {
        cm.IsOpen = Model.ShowDisplayHistory;
        e.Handled = true;
    }
}


这篇关于禁用上下文菜单WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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