I have a window (with on-screen keyboard) on top of a user control of another window.
I want when the user clicks outside of the keyboard window, the keyboard window to be closed. For this I'm using the onlostFocus and Deactivated events, in which i call the method HideKeyboardWindow().
In the user-control I have a grid with 1 row. When the keyboard is open and I click on the row of the grid, HideKeyboardWindow() isn't called. However, when I wrap the row with a ScrollViewer, then HideKeyboardWindow() is called.
Why is the scrollviewer messing with the focus?
The GotFocus event is not a good event to use for your purpose because it can be raised at inappropriate times, such as when the user mouses over the inner controls of your keyboard for example. A better solution would be to simply attach an additional MouseDown handler to the parent control. When the parent handler receives the event, the user has clicked outside the keyboard control.
Related
I couldnt get the GotFocus() event fired in the WPF window by clicking. But if I click any controls, it will be fired.
My requirement is as follows: I have a hostwindow which has a viewport with two datagrids which can host user controls. I do animations like flip and fade on this user controls. I am using a transparent background(glass effect) for the controls. But when one user control get on top of the other, both of them overlap. So I want to make the top one opaque when the user click on one user control.
Try using the Activated event, as GotFocus is intended to be used only with controls.
i have a Panel which contains an arbitrary number of child controls:
If the mouse enters one of the child controls in the Panel:
Then the MouseEnter event of the Panel is not fired.
Note: A related problem is that if the mouse moves from the the panel to one of the child controls, then the Panel's MouseLeave event is fired:
Even though the mouse did not leave the panel.
How can i cause the MouseEnter event of a Panel to fire if the mouse enters "any" control that is a child on the panel?
Something like:
foreach (Control ctrl in panel1.Controls)
ctrl.MouseEnter += panel1_MouseEnter;
I have a silverlight templated control that changes opacity when you hover it . However when user points cursor to its child control the effect wores off. I want to have the control highlighted also when the user hovers any child control. I've did the same thing in WinForms by overriding the WndProc method. Is there something similar in silverlight ?
Thanks
Sounds to me like you have not used the correct events to detect the hover, I suspect you are using MouseMove. Instead Use MouseEnter and MouseLeave events. An MouseEnter event will occur when the mouse moves over the control. You move the mouse over child controls and you will get no further events. Then when the mouse moves completely out of your control you will get MouseLeave.
I have a small Silverlight 4 app that essentially consists of a grid containing a label and a combo box. When I click the label, I replace it with a second text box so that I can edit the label (much the way you can edit the name of a Silverlight control in VS2010).
I have a LostFocus event handler on the text box that will end editing when the control loses focus (restoring the updated label). Trouble is, users tend to click on the panel when they are done editing rather than on another control (or hitting Enter, which is also supported).
I tried adding a left mouse down event handler to the panel. However, that only fires when the text box does not have the focus (I guess the text box captured the mouse?)
Is there an approach to recognize that a non-input control was clicked that would enable me to terminate edit mode?
You can subscribe to Grid's MouseLeftButtonDown routed event using the following code:
panel.AddHandler(UIElement.MouseLeftButtonDownEvent,
new MouseButtonEventHandler(panel_OnMouseLeftButtonDown), true);
Unlike common events routed events are bubbled from innermost control to its parent, then to grandparent etc. In the same way you could subscribe to panel's parent to intercept clicks outside your panel.
I want to get notified when I click a window in WPF (I use the GotFocus event), but it only triggers when I click on a Combobox in the window. What I want is to get notified when the the window or any of the controls in the window is clicked. Any ideas of how to do this?
The GotFocus event doesn't get fired when the Window gets focus, it's intended to be used with controls only. The Activated event serves this particular purpose.
Use Activated event instead of GotFocus.
You could try the IsKeyboardFocusWithinChanged event. It should trigger when the keyboard focus is taken by an element of the window, or when it is taken by another window