0

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:

enter image description here

And if I want to do it programatically I just dont have any MouseEvent:

enter image description here

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Andres
  • 2,729
  • 5
  • 29
  • 60
  • 2
    It exists but it is hidden. Because it can never work, the WPF element gets the mouse messages. – Hans Passant Mar 10 '13 at 02:47
  • 1
    I tried converting the elementhost to control. Then i create the event. I succeded, but it never fires. Seems the only way is q you say. Catching the mouse enter in the elementhost child (usercontrol) directly. – Andres Mar 10 '13 at 22:03

1 Answers1

3

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");
        }

    }
KF2
  • 9,887
  • 8
  • 44
  • 77