- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 WindowsFormsHost 中有一个 Forms.DataVisualization.Charting.Chart。我无法让图表接收鼠标滚轮事件。点击正在工作,如果我尝试使用 Forms.TextBox,鼠标滚轮也可以工作。如果我在“ native ”表单应用程序中使用图表,鼠标滚轮也可以工作。
所以,造成问题的原因是表单图表在 formsHost 中的组合。
这是一个非常简单的应用程序来复制问题:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Name="TextBlock1" Grid.Column="1" />
<WindowsFormsHost Name="WindowsFormsHost1" Grid.Column="0"/>
</Grid>
以及背后的代码:
public MainWindow()
{
InitializeComponent();
var chart = new Chart() { BackColor = System.Drawing.Color.Aquamarine};
WindowsFormsHost1.Child = chart;
chart.MouseDown += (a, b) => TextBlock1.Text += "FORMS click\r\n";
TextBlock1.MouseDown += (a, b) => TextBlock1.Text += "WPF click\r\n";
chart.MouseWheel += (a, b) => TextBlock1.Text += "FORMS wheel\r\n";
TextBlock1.MouseWheel += (a, b) => TextBlock1.Text += "WPF wheel\r\n";
}
我可以接收来自 wpf 的所有点击和鼠标滚轮,但无法接收来自表单的滚轮。我也尝试了 formsHost 的轮监听器,但没有成功。
有什么想法吗?乔恩·斯基特?
最佳答案
这是 Windows 窗体 (WinForms) 和 WPF 之间的常见互操作性问题。 WPF 事件的行为有所不同,它们使用路由事件而不是 Windows 窗体的旧事件处理。
WinForms 本身是 Win32 世界的消息处理映射,因此在 WPF 上嵌入 WindowsForms 控件时必须手动对其进行编码。为了处理鼠标单击以外的鼠标事件(包括鼠标滚轮),您必须代理 winforms 事件。
.NET 4的MSDN库明确提到了这一点:
Surrogate Windows Forms Message Loop
By default, the System.Windows.Forms.Application class contains the primary message loop for Windows Forms applications. During interoperation, the Windows Forms message loop does not process messages. Therefore, this logic must be reproduced. The handler for the ComponentDispatcher.ThreadFilterMessage event performs the following steps:
1.Filters the message using the IMessageFilter interface.
2.Calls the Control.PreProcessMessage method.
3.Translates and dispatches the message, if it is required.
4.Passes the message to the hosting control, if no other controls process the message.
当窗口句柄被销毁时,WindowsFormsHost 控件将从注册中删除自身。
欲了解更多信息,请访问: http://msdn.microsoft.com/en-us/library/ms742474.aspx
关于wpf - WindowsFormsHost 中的 WIndows Forms Chart 不接收鼠标滚轮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7414117/
我相信绝大多数小伙伴在自学python时,运用pycharm进行编写程序时发现字体太小不方便进行编写,通常像codeblocks这样的编程软件可以通过“ctrl+滚轮”进行放大和缩小。而
在我的应用程序中,我使用了 Scroller零件。我似乎无法弄清楚我应该在哪个事件上设置一个监听器以便知道何时滚动内容。我试过Event.CHANGE在 Scroller.verticalScroll
我正在使用一个简单的 progressDialog,它运行正常但轮子没有进步: //Progress Dialog final ProgressDialog dialo
我想在点击文本字段时关闭键盘,以便为该文本字段下方的选择器留出空间。 struct ContentView: View { @State private var date = Date()
我是一名优秀的程序员,十分优秀!