[英]WPF | WindowFormHost | WebBrowser | Context Menu
I am trying to write an application where users can highlight text in a browser and mark the contents via the context menu. 我正在尝试编写一个用户可以在浏览器中突出显示文本并通过上下文菜单标记内容的应用程序。 I have a WPF application and I am using the WindowsFormHost with a Windows Forms WebBrowser so I can have a custom context menu.
我有一个WPF应用程序,并且我将WindowsFormHost与Windows Forms WebBrowser一起使用,因此可以使用自定义上下文菜单。 My problem is that I cannot get the Click event to fire.
我的问题是我无法触发Click事件。
Am I doing something wrong? 难道我做错了什么?
public partial class MainWindow : Window
{
public MainWindow()
{
InitalizeComponent();
System.Windows.Forms.WebBrowser Browser = new System.Windows.Forms.WebBrowser();
Browser.IsWebBrowserContextMenuEnabled = false;
System.Windows.Forms.ContextMenu BrowserContextMenu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem MenuItem = new System.Windows.Forms.MenuItem();
MenuItem.Text = "Take Action";
MenuItem.Click += new System.EventHandler(this.MenuItem_Click);
BrowserContextMenu.MenuItems.Add(MenuItem);
Browser.ContextMenu = BrowserContextMenu;
WindowsFormsHost.Child(Browser);
}
//THIS DOESN'T FIRE!?!?!?
private void MenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Click!");
}
}
将所有内容移至Main_Loaded并成功
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.