问题
I have a Winform with an elementHost in it to contain a WPF UserControl. What I need, is to do something when the mouse enters the elementHost, not the child. I was trying to use MouseEnter event in the elementHost but it does not exists. Is there any chance I can do this? Or is it just not possible? It´s curious to not have mouse events on them.
This are all the events I have:
And if I want to do it programatically I just dont have any MouseEvent:
回答1:
MouseEnter
event located in HostContainer
of elementHost,for detect when mouse enter try following code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
elementHost1.HostContainer.MouseEnter += new System.Windows.Input.MouseEventHandler(HostContainer_MouseEnter);
}
void HostContainer_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
MessageBox.Show("Mouse entered");
}
}
来源:https://stackoverflow.com/questions/15177486/mouseenter-event-in-winform-elementhost