I have a WrapPanel that has a button as a child element. Both the WrapPanel and the Button have the PreviewMouseLeftButtonDown event defined.
I have noticed that when I click the Button, the WrapPanel's event is fired before the Button's event. Is there anyway to change that?
Because Preview* events are tunneling, they travel from the root to the source, so they are raised on the panel, which is closer to the root, first. Use the bubbling version (MouseLeftButtonDown) to have the event travel up the tree.
When you set the property IsHItTestVisible to false then mouse triggered events like a clicks will be ignored.
Related
I have an ItemsControl that Contains a few buttons, My Items control is movable, you can move it around by dragging it. the issue is when I click and drag my control to move it, and leave the mouse on top of a button inside the control, it fires the click event of the button which I dont' want/
So While I am moving the control around I want to disable any events on the child buttons, I used IsDisabled = true but that changes the appearance of the buttons too which I dont want.
you can set IsHitTestVisible property of button to false
IsHitTestVisible="False"
I am playing around with mouse events and I realized there are a bunch of events but I have no idea when to use which one.
There is the Click event, MouseDown event, PreviewMouseDown, PreviewLeftButtonMouseDown, LeftButtonMouseDown.
What are the differences between then? They all do the same and that is notifying once mouse being pressed.
When shall I use which for what?
Click event : The user has clicked the element and released the button
MouseDown event: The user has pressed the mouse button (before releasing it). Click happens to be called if the user has both pressed and release it on the same element.
PreviewMouseDown : same as mousedown, except it is a tunnel event. It is called on parent function first, then tunneled to the child container while mousedown bubbles upwards (on child container first, and then on parent containers).
LeftButtonMouseDown : Called when left mouse button is pressed
PreviousLeftButtonMouseDown : I am not sure about this event. Could not find it. Did you mean PreviewLeftButtonMouseDown?
The TabIndexChanged event of the Windows Forms TabControl doesn't fire when I change between tabs. But the SelectedIndexChanged event is fired.
What is the explanation for this?
The TabIndexChanged event fires when you change the TabIndex property of the control-- the order of controls related to the parent form, etc. It has nothing to do with when the user is switching tabs.
Besides the SelectedIndexChanged event, you probably want to explore the Selected, Selecting, Deselected, and Deselecting events to determine what to do when the user is changing tabs.
I'm having a problem when the Silverlight toolkit's ContextMenu is clicked while it is over a UIElement that has registered a Tap event GestureListener. The context menu click propagates to the underlying element and fires its tap event.
For instance, say I have a ListBox and each ListBoxItem within it has registered both a ContextMenu and a Tap GestureListener. Assume that clicking context menu item2 is supposed to take you to Page1.xaml, while tapping on any of ListBox items themselves is supposed to take you to Page2.xaml.
If I open the context menu on item1 in the ListBox, then context menu item2 is on top of ListBox item2. When I click on context menu item2 I get weird behavior where the app navigates to Page1.xaml and then immediately to Page2.xaml because the click event also triggered the Tap gesture for ListBox item2.
I've verified in the debugger that it is always the context menu that receives the click event first. How do I cancel the context menu item click's routed event propagation so it doesn't reach ListBox item2?
Thanks for your help!
You can get around the problem by doing the following:
In the context menu's Opened handler set LayoutRoot.IsHitTestVisible (LayoutRoot is the default name for the root UIElement) to false
In the context menu's Closed handler set LayoutRoot.IsHitTestVisible back to true
You could try adding a rectangle with a transparent background (important) over the effected area/page when showing the context menu.
I had a very similar issue, but I am using the ManipulationCompleted event as a "tap" detector as the object the ContentMenu applies to is a custom control.
LayoutRoot.IsHitTestVisible didn't work for me, perhaps because it does not apply to Manipulation events. However, it set me on the right path. I just implemented my own simple equivalent of it - I created a boolean variable bCancelManipulation in the page's scope.
In the ContentMenu's Opened event set it to True.
In the ContentMenu's Closed event set it to False.
In the ManipulationCompleted function, the first thing I do is check
if(bCancelManipulation==true) { return; }
It's kind of a hack, but it works great and is quite simple to code - it can easily be adapted to a Tap event too.
I cant get mouseleave to fire inside a ribboncombobox inside a ribboncontrolgroup inside ribbon tab inside a ribbon.
I have a behavior that on mouse enter opens the dropdown and should close it on mouseleave
except mouseleave doesnt fire I verified this using snoop and by setting a breakpoint on the event.
Any ideas or workarounds?
I was having a similiar issue with the border control - and I found an event called, "IsMouseDirectlyOverChanged" - that seemed to fire pretty regularily so I used that.