Is there any way to make WPF adorner ignore mouse entirely so that the UIElement behind the adorner still gets mouse events as if the adorner does not exist?
Set the IsHitTestVisible property of the Adorner to false
If you use the tunneling version of the mouse events rather than the bubbling events (i.e., PreviewMouseDown instead of MouseDown), you will receive the mouse events from the UIElement first, and be able to stop them from reaching the adorner by setting e.Handled to true.
Related
Canvas KeyDown Event not working
I have set KeyPreviou on my form to true.
I have set canvas Focusable to true.
I Focus on my canvas control when Mouse is pressed
Any info on this matter did not help me.
Any ideas?
Finally i found what the problem was. I posti it so others will benefit.
Initially i focused on my canvas inside the MouseDown event.
Now i focused on the canvas inside the MouseUp event and all working ok.
I have a quite complex view with multiple tabs inside tab control. On one tab there is a control with adorner layer. Adorner layer calling CaptureMouse in MouseLeftButtonDown event handler to capture mouse input. Everything works fine.
But if I switch tabs on the view in particular order and then click on adorner layer it fails to capture mouse input: CaptureMouse() returns false. The same time Mouse.Captured returns null. Control that hosts adorner layer continues to work fine and even able to capture mouse.
Can't provide any code because there are many custom controls in action. In simplified layouts everything works fine.
Any suggestions why CaptureMouse may fail?
If the IInputElement is a UIElement or a UIElement3D, IsVisible and IsEnabled must be true.
If the IInputElement is a ContentElement, there is no IsVisible so just IsEnabled must be true. This is of course at the time you call Mouse.Capture. Also, the PresentationSource for the IInputElement's containing visual must have an IMouseInputProvider.
I think the problem here is either another element immediately taking capture, or IsVisible being false at the time you call Capture.
Make sure that in the MouseLeftButtonUp event handler you're calling ReleaseMouseCapture() otherwise your original adornerlayer will hold on to it.
Also check to ensure that you don't have any controls further up the chain that are also capturing the mouse (you can set handled to true in your adorner layer to prevent that)
Edit: Also make sure IsEnabled is true.
I have a third-party image control inside an SL5 listbox itemtemplate. This makes for a nice scrollable gallery of images.
Now for the trouble: the third-party image control (LeadTools v17.5) has an interactive feature wherein mouseleftbuttondown causes a draggable magnifying glass to appear. This works great when the control is not hosted in a listbox. But clicking on the control within a listboxitem does nothing. After some research I "believe" this is because the listboxitem is trapping the mouseleftbuttondown event marking it as handled so the image control never sees it. In my application I have no need to handle the mouseleftbuttondown event at the listbox level (other buttons etc control my UI). Assuming I'm correct, is there a way to stop the listboxitem from listenting to this event?
Or perhaps I'm completely wrong about the cause. In that case any other ideas about why the listbox appears to block mouseleftbuttondown events from reaching the controls within is appreciated.
Thanks,
Mark
Instead of trying to keep the ListBoxItem from handling the event, you might be able to use UIElement.AddHandler with handledEventsToo: true, if you can get the necessary UIElement and Delegate references to trigger the image control's feature.
Thanks for your suggestions. In this case it turns out the quick solution was to add this handler to the image control:
private void leadGalleryImageViewer_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
e.Handled = true;
}
From this I gather the mouseleftbuttondown event was being received by the image control all along, but likely as it bubbled up through the listitem and beyond, the listitem did its thing then marked it as handled effectively killing anything the image control was trying to do. By marking the event as handled at the image control level, the listitem ignores it.
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.
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.