Answer the question
In order to leave comments, you need to log in
How to send an event to the element with focus?
Hello. There is a TextBox. It has an event handler for the rotation of the mouse wheel. But if the mouse is not over the textbox, then the event does not fire, although the element is under focus. How can I make it catch the mousewheel event when it's under focus, even if the mouse pointer is somewhere else?
Answer the question
In order to leave comments, you need to log in
The easiest option is to create a PreviewMouseWheel event near the window (Preview so that the event is called on all child elements) and inside check if the TextBox has focus.
private void TextBox_MouseWheel(object sender, MouseWheelEventArgs e)
{
MyFunc();
}
private void Window_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
if (tb.IsFocused)
{
MyFunc();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question