Reputation: 787
I have a WPF application that is using a WindowsFormsHost control to host a control of Windows.Forms.
I tried to implement the MouseWheel event - but it seems that the the MouseWheel event never fired.
Is there a workaround for this issue?
Upvotes: 5
Views: 3396
Reputation: 11926
A workaround is to use event MouseEnter.
Suppose you have a winform label in a WindowsFormHost
In XAML
<WindowsFormsHost Height="100" Name="windowsFormsHost1" Width="200" />
In C#
System.Windows.Forms.Label label = new System.Windows.Forms.Label();
label.Text = "Hallo";`
label.MouseEnter += new EventHandler(label_MouseEnter);
label.MouseWheel += new System.Windows.Forms.MouseEventHandler(label_MouseWheel);
windowsFormsHost1.Child = label;
.....
void label_MouseEnter(object sender, EventArgs e)
{
(sender as System.Windows.Forms.Label).Focus();
}
void label_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
(sender as System.Windows.Forms.Label).BackColor = System.Drawing.Color.Red;
}
Now MouseWheel should work (label shoud change color)
Upvotes: 8
Reputation:
one thing im gonna add... if a child of WindowsFormsHost is a Windows.Forms element then this link helps.
http://vastpark-svn.cvsdude.com/public/trunk/src/Sample.Client/WPFInputSource.cs
why im posting is i was looking for a solution and found.. so i thought it might be helpful somebody in the future. anyway, thanks for asking here first^^
Upvotes: 1