Highlighting control when mouse is over child control - silverlight

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.

Related

Scrollviewer messing with focus

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.

Window GotFocus event not firing

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.

previewmousewheel not getting raised when mouse is not on the control in wpf

I have a combobox control's previewmousewheel event been handled. When my mouse is on the control and i move the center wheel of my mouse then this event gets raised. But when my mouse is away from the control and i move the center wheel of my mouse then this event does not get raised.
Can anybody please explain me why is this happening?
If I want to raise an event when my mouse is away from the control then which event should I handle?
This is expected behaviour.
If the mouse cursor is not positioned over the control then no mouse events are routed through it. You wouldn't expect a mouse click event to be routed through it if the cursor was over a different control would you?
If you want this behaviour then I would suggest that you handle the mousewheel event in the page/view and route it from there, be cautious though as user expectation is for mouse and keyboard events to be handled by the in focus item.
In those cases that the user would expect the event to be forwarded to the control you could use Mouse.Capture(someControl) and Mouse.Capture(null) to stop the forwarding.
You should only use this when it makes sense. E.g. when dragging a scrollbar, when you started to drag on the thumb but are not required to stay on top of it as long as you keep the left mouse button down.
When using Mouse.Capture() make sure you always provide a way back from capturing.

How do I capture the mouse when a Silverlight RepeatButton is depressed?

I have a RepeatButton on a UserControl that acts as the up button. The control is a number spinner of sorts. When the number value goes from 9 to 10 the up button is released because it moves out from under the mouse. I know I can capture the mouse, but my RepeatButton is not giving me MouseLeftButtonDown events. So how do I capture the mouse over the RepeatButton when it is depressed and release the capture when it is released? And should the RepeatButton give me MouseLeftButtonDown events?
Edits:
It would seem that the template content is stealing the button's MouseLeftButtonDown events. Is there anyway I can circumvent the button's content. If I set HitTestVisible to false, the button itself becomes untouchable. I wish silverlight had OnPreview overrides.
Have you tried utilising MouseLeftButtonUp instead to check if it can occur when the mouse button is released?
I just had a similar problem with Windows 8/WinRT and found a workaround - you can bind something to the button's IsPressed property and when it gets set to false - it means the button/touch is up.

WPF richtextbox selection problem

i have two richtextboxes one below the other in my application.when the user start selection in one richtextbox and continue to the other richtextbox selection should automatically move to the second richtextbox.is there any way to do this type of selection.
thanks in advance,
dhyanesh
You'd think you could use MouseEnter and MouseLeave, but when the mouse is captured (as it is during text selection), these events don't fire as expected.
The way to achieve your goal is:
Subscribe to MouseMove on the first RichTextBox.
In the MouseMove event, check Mouse.Captured to see if it is the RichTextBox.
If the mouse is captured, do a hit test on the mouse's current postion using VisualTreeHelper.HitTest. Go up the visual tree from the value of HitTestResult.VisualHit to see if the mouse is over a RichTextBox other than the current one.
If the mouse is over a new RichTextBox, cancel the mouse capture with Mouse.Capture(null), then fire a MouseLeftButtonDown event on the new RichTextBox to cause it to capture the mouse and begin selection.

Resources