- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个 WPF 控件,该控件托管在 Word VSTO AddIn (WinForms) 中。现在我遇到了上下文菜单上的鼠标单击事件的问题。
如果我单击左半部分(WinForms 应用程序上方的部分)的上下文菜单项,则单击将直接转到 WinForms 应用程序,并且我的上下文菜单不会收到该事件。
如果我单击该项目的右半部分(WPF 表单上的部分),一切都会按预期工作。
有人可以帮我解决这个问题吗?
最佳答案
非活跃博客的答案是:
声明类级别调度程序框架对象
System.Windows.Threading.DispatcherFrame _frame;
订阅菜单的 GotFocusEvent 和 LostFocusEvent:
_menu.AddHandler(System.Windows.UIElement.GotFocusEvent,new RoutedEventHandler(OnGotFocusEvent));
_menu.AddHandler(System.Windows.UIElement.LostFocusEvent, new RoutedEventHandler(OnLostFocusEvent));
下面是 GotFocusEvent 和 LostFocusEvent 事件过程的实现:
private void OnGotFocusEvent(object sender, RoutedEventArgs e)
{
if (LogicalTreeHelper.GetParent((DependencyObject)e.OriginalSource) == _menu)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal (DispatcherOperationCallback)delegate(object unused)
{
_frame = new DispatcherFrame();
Dispatcher.PushFrame(_frame);
return null;
}, null);
}
}
private void OnLostFocusEvent(object sender, RoutedEventArgs e)
{
if (LogicalTreeHelper.GetParent((DependencyObject)e.OriginalSource) == _menu)
{
_frame.Continue = false;
}
}
就我而言,不需要 if 语句,我订阅了这样的事件
<EventSetter Event="GotFocus" Handler="contextMenu_GotFocus" />
<EventSetter Event="LostFocus" Handler="contextMenu_LostFocus" />
关于WPF ContextMenu 单击路由到 WinForms 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11609874/
这个问题在这里已经有了答案: How to configure ContextMenu buttons for delete and disabled in SwiftUI? (4 个回答) 4 个月
我在弄清楚如何设置正确的 DataContext 时遇到了一些麻烦。在 ContextMenu . 我有一组 View 模型,它们是 ItemsControl 的来源.每个 View 模型都有一个项目
我正在寻找一个关于在 WPF 中设置 ContextMenu 和 ContextMenu Items 样式的好例子。我想要的是 ContextMenu、Menu 和 MenuItems 如何一起玩的分
我的 WPF XAML 中定义了一个上下文菜单,如下所示: 我使用 System.Windows.Forms.NotifyIcon“myIcon”作为我的托盘
我在基于 Canvas 的 WPF 中制作了一个非常漂亮的 NodeGraph,现在我正在通过右键单击菜单添加漂亮的功能。 这些菜单是上下文相关的。这意味着右键单击图表的背景将显示图表上下文菜单,而右
如何复制我在一个 ContextMenu 中创建的 MenuItem 并将其复制以便我可以在第二个 ContextMenu 中使用它? 我试图直接复制它并删除它,但我得到元素已经有一个逻辑父元素。它必
registerForContextMenu(validate_button); @Override public void onCreateContextMenu(ContextMenu m
我正在使用 jquery contextmenu plugin这是我的 DEMO 下面是我的代码: $(function () { $.contextMenu({ sele
我正在使用 MVVM 将 View 绑定(bind)到树中的对象。我有一个实现树中项目的基类,该基类有一个 ContextMenu 属性: public IEnumerable Context
在旧 View 模型中有一个 ContextMenu 属性 ` public static ContextMenu DropDownMenu { get { return _Dr
Chrome 会触发 contextmenu 事件,但不会触发右键单击的 click 事件。 Firefox 会触发两者。 我正试图找到一些官方引用或解释,我很惊讶我从来没有遇到过这个。 http:/
默认情况下 JavaFX TextField有一个内置 ContextMenu带有“撤消”、“复制”、“剪切”等选项。 ComboBox也有同样的ContextMenu当它被设置为可编辑时( Comb
右键单击后,我一直坚持管理上下文菜单。实际上,我需要为文件夹显示一些上下文菜单项,为文件夹显示一些上下文菜单项。 单击文件夹上下文菜单将如下所示: create remove rename new 单
我正在尝试为 ScrollBars 替换 ContextMenu,我已经编写了这段代码:
我有一些 ContextMenu 和一些 menuItems。 menuItems 之一是“添加项目...”。当用户选择这个项目时,他应该看到带有可用项目列表的子菜单; 这是我的上下文菜单的描述: A
我想使用 jQuery.contextMenu: http://abeautifulsite.net/blog/2008/09/jquery-context-menu-plugin 在 jQuery.
我有包含多个项目的 ListBox(SelectionMode=Extended),我想添加上下文菜单功能。问题是如何根据某些条件动态创建上下文菜单。例如。如果只选择了一个项目,我想显示常规上下文菜单
我有一个通过数据绑定(bind)获取菜单项的上下文菜单(我使用的是 MVVM 模式): 这工作正常。但是,在没有要显示的菜单项的情况下,我根本不希望显示上下文菜单。有没有办法做到这一点?某种 XAM
我正在学习javafx.scene.control.ContextMenu,现在我面临一个问题: 如何从EventHandler获取被点击的对象? event.source() 和 event.tar
所以我有一个复杂的上下文菜单。它不只是菜单项。它也有单选按钮,底部有一个堆栈面板,上面有一个整数上下框。
我是一名优秀的程序员,十分优秀!