PreviewMouseDown Intercepting SelectedItemChanged Event - wpf

I've got a TreeView which acts as the main way of navigating a WPF application.
When the user selects a new item in the TreeView if the page they're leaving has unsaved information we offer the chance to cancel the move to continue working on the current data/save it. This currently happens in the PreviewMouseDown event handler.
It seems however that throwing up a dialog that offers a yes/no/cancel option here prevents the SelectedItemChanged event from ever actually firing, I assume because another mouse click has occured. As a result, if they decline the option to stay on the current page, it's still not changing.
Is there any way to re-fire the event from within PreviewMouseDown so that the SelectedItemChanged event still gets called?

Is there any way to re-fire the event from within PreviewMouseDown so that the SelectedItemChanged event still gets called?
It would be easier to call the event handler manually just as you would call a method. Or better yet, break out the code in the event handler to a standalone method that you call from both the PreviewMouseDown handler and the SelectedItemChanged handler.
The other option would be to change the SelectedItem or IsSelected property so the event fires again.

Related

ExtJS 6 Check if event was fired programmatically

How I can check if event was fired programmatically?
Namely I have an Ext.tree.Panel and listen for it selectionchange event. How I can check within handler if event was fired manually by user (row click) or via select() method?
option 1 :
For most of the events eOpts arguments is passed to event. Depending on the event this is fill by ExtJs. If event is fired manually thus eOpts is never filled or filled customly.
option 2:
If manual event firing is happens in code you can manipulate add a custom argument
As far as I know and my research there is no solution based on scope of selectionchange event. However from a design perspective this is how it should be since selectionchange event should not depend on caller. From what is told I can say that 2 different event is needed. Where different action is taken. (which is the definition of an event :))
Therefore my suggestion is to override select method and fire a custom event in which you do what you want do differently. If needed in rowclick event another custom event can be fired.
You can override this in subclasses or you can use Ext.override for global scope.
You can't, really. The "best" way would be to listen for an itemclick event and check whether the selectionchange event fired within some small threshold amount.

Strange issue - mouse click in popup is getting captured by control underneath

I'm displaying a Popup in response to a button click (popup.IsOpen = true;). The popup contains a ComboBox, and when I click an item in the combobox, one of the things the SelectionChanged event does is to hide the popup.
The Popup appears over a DataGrid that I also have on my page, and I'm finding that the mouse-click on the combobox is also being picked up by a MouseUp event that I've got on the DataGrid. Any idea what's going on?
The MouseUp Event has a routing strategy of type Bubbling. Events that use this type of strategy get passed up the chain to parent controls. Since the Popup is a child of the DataGrid, the event will "bubble" up to the DataGrid. If you would rather the event not bubble, you can try using PreviewMouseUp, which has a Tunneling routing strategy, and will "tunnel" down the chain to child controls. Here is a decent overview of Routing Strategies.
I've hit the same issue. Oddly, it doesn't happen when the code is run in the debugger - it only happens in the release version. It really seems to be a bug in WPF. Trying to catch the click and set the event to handled doesn't work.
My workaround is to, when the popup opens, to tell the control underneath to ignore the click.

RibbonComboBox MouseLeave Event doesnt fire

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.

DataGrid.LoadingRow event firing three times

I have a HyperLinkButton in every row of a datagrid in my silverlight app. I need to fire an event so I am adding a handler to the click event of the HyperLinkButton in the DataGrid.LoadingRow event. The problem is the event is firing three times (more accurately, the handler is being added three times. I tried removing the handler before adding it but that has no effect. Any ideas?
I just set the .Tag on the Hyperlink button when I add the event handler and use that as a flag that the handler has been added.
To add to this issue, the problem occurs probably because the LoadingRow event may actually fire several times. The Datagrid will only instantiate the row when it is needed and will recycle it when it goes out of view. Like when you start scrolling the grid.
See the remarks sections for details:
DataGrid.LoadingRow event on msdn

ContactUp event not fired

In my surface application I have a SurfaceWindow with a SurfaceUserControl on. On the SurfaceUserControl I have a SurfaceButton but the ContactUp (and down) event is not fired. The ContactHoldGesture event is fired though.
Any ideas?
Could you include some code to reproduce? Where are you subscribing to those events?
Most likely what's happening is the contact up and down events are being handled by the button, so they don't fire at the usercontrol level. Try looking at the previewcontactup and previewcontactdown events.
ContactUp and ContactDown are handled by the button itself - that's why the events never get to your code. If you really want to intercept these events, use PreviewContactUp/PreviewContactDown instead. What you probably really need though is to just handle the Click event on the button. Adjust the ClickMode property of the button if you want to change what causes the Click event to be raised.

Resources