WPF MouseWheel and KeyDown not called without input focus? -


I have a custom class (items container) in which there are some buttons & amp; UserControls

I use the navigation system and mouse & amp; The input, and the user can 'pan' using the right-click ... but not my way to 'mousewheel' and 'keydown' unless the user clicks on some interactive (buttons, etc.) Are called.

The best article I found so far I needed to 'hook' in every control !! It seems silly to parse every single scene node and add event handlers everywhere ... there should be an easy way.

Is there there?

There are some items added in the need to address this question.

The first one is that a routing event will spread beyond the tree and above the tree. So if you have embedded such controls in control ...

  & lt; Grid name = "MyGrid" & gt; & Lt; StackPanel & gt; & Lt; Button & gt; Button 1 & lt; / Button & gt; & Lt; Button & gt; Button 2 & lt; / Button & gt; & Lt; Button & gt; & Lt; TextBlock & gt; Button 3 & lt; / TextBlock & gt; & Lt; / Button & gt; & Lt; / StackPanel & gt; & Lt; / Grid & gt;   

... MyGrid on keydown attaching an event to control behavior; There will be any keydown routing event from within your children

There is a warning that if the incident scene is controlled by a control within the tree , Which is the button control and the MouseLeftButtonDown routing event; Then you will need to adjust how you register. It is quite simple and can be done this way; Where true indicates that you want to know that another handler handled the event. MyGrid.AddHandler (UIElement.MouseLeftButtonDownEvent, New Routing Aventahandler (mouse leftbutttondown), true); } Private zero mouse left buttondown (object sender, routing adventure e) {console.light line ("mouse left button fire"); }

If you wanted to proceed through a debugger, you would see that when you click on the text, the source of the routing ad button3 actually TextBox .

This will satisfy your need to hook into different controls; Since you can avail of different routing events

The focus should still be present somewhere within the application; Which can easily be set through parental control and call focus .

Comments