Handling PointerEntered and PointerReleased but passing Click/Tap to parent element - c#

I have a Grid and inside the grid, I have Buttons. I need PointerEntered and PointerReleased events as I need to track which buttons are hovered. The problem is that, I need my Grid to handle the click events. Even though I don't have a click/tap/press handler for the button, my button captures the click and doesn't bubble it up to its parent (Grid). If I disable the button by settin IsEnabled to false, the click event is bubbled up to the Grid correctly, but then PointerEntered and PointerReleased events aren't fired, which I need to handle on the button. How can I handle enter/release events on the button and at the same time, pass the click event to its parent? I need my Grid to go onto "clicked" state as I also listen for the PointerReleased event on it. If click doesn't fire, released doesn't fire even if I do release the mouse button when on the Grid.
Thanks,
Can.

Try using AddHandler to attach a click event to grid and see if it works for you.
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.addhandler.aspx
Remember to remove the event using RemoveHandler when done.

Related

C# Forms - Only the first of what should be two consecutive events triggers

I have a TextBox with a "Leave" event and a Button with a "Click" event. There is no code in either event handler.
If I place the cursor in the TextBox then leave it by clicking any other item, the "Leave" event triggers.
If I place the cursor anywhere except in the TextBox and click the Button, the "Click" event triggers.
However, if I click the Button with the cursor inside the TextBox, only the "Leave" event triggers.
How can I get both events to trigger in the third scenario?

Winforms control LostFocus event not firing when you click the form background

I have a custom ComboBox which opens a separate control when you click on the arrow of the ComboBox. I would like to call the 'LostFocus' event handler to close the custom control when you lose focus of the ComboBox.
This works fine if you click onto another control such as a text box, however doesn't fire if you click on the background of the form.
I want to mimic the functionality of when you click off and close the dropdown of a normal combobox.
Take a bool variable at Form level and make it true during combobox enter(GotFocus) event. InLeave(LostFocus)event ofcombobox, make itfalse`.
Subscribe to Form MouseClick event and check bool variable in this event. if true , call combobox leave event here.

Image MoueUp event vs Button Click event

I have seen that many users have asked how to make a clickable image in WPF.
Image has Mouseup event. It works like Button click event as I understand.
Is there any difference in Image Mouseup event and Button click event?
Mouseup event, user can click somewhere else on the screen and hold down the click button and move the pointer to Mouseup element, and then release the mouse.
Click event requires both the mousedown and mouseup event to happen.
The MouseUp can happen in a different control from MouseDown.
A Button can also be bound to a Command and thus separating your logic from the UI.

Prevent Click events on child view while swiping(flicking) parent. WinPhone8.1

I have canvas with listbox inside it.
each child element of listbox sets eventhandler for Click event.
On canvas I set eventhandlers for
ManipulationStarted="canvas_ManipulationStarted"
ManipulationDelta="canvas_ManipulationDelta"
ManipulationCompleted="canvas_ManipulationCompleted"
My code for swiping works perfect accept one thing, it fires Click eventhandler before ManipulationCompleted eventhandler.
But for example listbox in the same time scrolls perfectly and do not fire Click event.
So basically what I need is to handle manipulation events in same way listbox do.
If this condition is true:
private void canvas_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
e.DeltaManipulation.Translation.X > [some value]
....
}
I need to disable firing Click event on any child element of canvas, doesn't matter if it is inside listbox or not.
Why are you setting click handlers if you don't want them to fire?
Click fires on pointer pressed, so there's no way to tell if the user wanted to Click or to start a manipulation. You'll need to either decide based on the location clicked or a later event if you want to differentiate between "clicks" and swipes.
Instead of Click you can handle the Tap gesture along with the manipulation events. Since Tap fires on the pointer released the manipulation system will fire it if the user tap and releases in one spot and it will trigger the manipulations if the user presses and moves the pointer.
See How to handle manipulation events for Windows Phone 8 for more details.

c# MouseUp is ignored while dragging an item to another panel

I try to drag an item from an ItemList to my TreeList. For that I wrote listView1_MouseDown, listView1_MouseMove, treeView1_MouseMove and treeView1_MouseUp functions. When I move the mouse within treeView1 borders, MouseMove event is handled as it was supposed to. But MouseUp doesn't fire. Am I doing something wrong?
Talking about Winfroms.
As far as I remember, MouseUp event is sent to the same control as MouseDown was sent to. So, in your case, your listView1 will receive MouseUp.
You might want to look into some other events, like DragDrop.

Categories

Resources