RibbonComboBox MouseLeave Event doesnt fire - wpf

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.

Related

PreviewMouseDown Intercepting SelectedItemChanged Event

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.

WPF: (SplitButton) MouseLeave won't fire without a click

I working on a WPF Ribbon application using a third party source (Syncfusion).
In my application I have a SplitButton with several CheckBoxes in it, I'm trying to implement MouseHover like action to my SplitButton so that on MouseEnter the DropDown will open and on MouseLeave the DropDown will close.
MouseEnter works great.
MouseLeave works great on a regular button (for changing the background for example) but on SplitButton it won't fire unless I press on the mouse (left or right button - it doesn't matter).
Any chance I could close the DropDown upon leaving the SplitButton without clicking on the mouse? Maybe by using another event?
Any help would be appreciated.

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.

Popup Never Closes

WPF is really getting me out of my nerves here. I configured a popup with some complex content (grid, buttons etc..). I set its StaysOpen property to False and IsOpen to True on a textbox MouseDown preview event.
Ths thing is that it opens but never closes when clicking anywhere outside the window.
Any suggestions?
Thanks!
UPDATE:
My popup has buttons inside. When I click one of those, the popup closes when I click outside of it. Is some weird stuff happening to the events routing?
Looks like the popup won't close if opened by any other control event. I just binded the IsOpen property to the IsChecked property of a ToggleButton to simulate a combobox.
Thanks for all your answers.
I was also having this issue, except on the PreviewMouseButtonUp event of a Button. The assumption that there is some bug with Popups and trying to open them in Tunneling events was accurate and led me down the path to my fix (which is a little more generic).
I needed to resolve this (the host control was generic / could be several types of controls) by listening for the bubbling event instead of the tunneling event, specifically with the AddHandler(RoutedEvent,Delegate,Boolean) method in order to capture handled events.
WAG the issue lies somewhere when transitioning from tunneling to bubbling.
I use code behind to initialize popup, and I've found that it's not closed if ran sync from other UI action like mouse event. To workaround this I run it async:
public static void ShowPopupMessage(string message)
{
DispatcherHelper.UIDispatcher.BeginInvoke(new Action(() =>
{
var popup = new Popup
{
Child = new AutoHideMessage(message),
StaysOpen = false,
IsOpen = true
};
}));
}
I set IsOpen on a textbox MouseDown preview event.
Set it to what? And where is the TextBox hosted?
I can only guess with the scant information provided, but I'd say when you click outside the Popup, your event handler is firing and opening it up again.
You can use LostFocus event of the PopUp. If the focus is not within the popup, set its IsOpen to false to close it.

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