When the WPF ComboBox is clicked and in-focus, the only interaction that occurs after that can be with the ComboBox. If anything else is interacted with, including the window functions (minimize, restore, close, resize) and any control in the window, the action is ignored and the ComboBox loses focus.
In addition, MouseEnter and MouseLeave on the window buttons are still active, but when MouseEnter on the window border(?) occurs, the mouse pointer does not change to the resize pointer. This behavior makes sense because of the ComboBox's use of the popup control. The popup control exists independently of the main visual tree and if i.e. the window moves or gets resized, the popup remains fixed floating above the main window.
I have tried using Reflector, to see what the ComboBox is doing, but I have not been able to find what I am looking for. Basically, I do not know if this behavior is coming from the window, the ComboBox, or if it has something to do with the popup. How can I solve this problem?
You're right on in your description there, the popup keeps all action focus until it itself loses focus. If you're trying to change the functionality of the ComboBox you may want to look at creating your own ControlTemplate that behaves differently and does not keep the default action of the popup control.
Hope this helps, not entirely sure what you're trying to do.
I know this question is old, but for anyone coming here looking for the answer, it is to use Mouse.Capture.
The ComboBox sets Mouse.Capture(comboBox, CaptureMode.SubTree) in OnIsDropDownOpenChanged. This ensures that all mouse events are captured by the ComboBox. When the Popup is closed Mouse.Capture(null) releases the mouse capture.
Related
Is there a way to make an entire WPF Window inert after a button click?
The window is invoked via Window.ShowDialog() and after use, the window is no longer needed for interaction but I leave it open to remind the user of the inputs in TextBox's, ListBox's, and give visual feedback via OxyPlot and so on. I leave it to the user to close the window manually.
One solution is to disable all buttons but that's tedious and it still leaves TextBox's functioning. That's not optimal because for anything to be functioning creates the wrong impression that the Window remains for anything other than looking at. It would be better for every control to be non-functioning by a single setting.
I did it by putting a name on the WPF window code behind and then setting .IsEnabled false upon the appropriate button click. All buttons, combo boxes, text boxes, and even OxyPlot became inert at that point and most parts were greyed out.
Consider creating a dedicated boolean dependency property in your code-behind or viewmodel and binding IsEnabled of every TextBox to the property.
I have created a custom popup to decorate my buttons with animated tooltips. I track Button.MouseEnter for the button to decide when to display the popup. I use Button.MouseLeave to determine when to hide the popup.
Problem is Button.MouseLeave is fired prematurely if the popup moves over the mouse cursor (its appearance is animated) despite the fact that I have set IsHitTestVisible = false for the popup and all its visual children.
Is this the way WPF is designed to work? I need MouseLeave to only fire when the cursor moves away from the button itself and not be influenced by the popup.
Thanks
I believe that the Popup control is actually contained within a window, which is why the popup can extend beyond the window bounds in some cases. (It's also why popup transparency is not supported in Silverlight.)
I believe that while the popup control is no longer processing "hits", the container window is, which is why you are losing your button's mouse focus.
I've not tested this, but you might try creating a template for your button and actually declaring the popup as part of the button (rather than below it). This may cause WPF to view the popup control as part of the button and eliminate the problem of losing mouse focus. This works in other scenarios, but I'm not 100% sure how this will work with a Popup.
EDIT: As a side note, the deault WPF tooltip allows you to override the template. I'm not sure what your goals are, but you may find it easier to change the appearance and behavior of the default tooltip than to try to roll your own, as a lot of these sorts of problems have already been solved in the default Tooltip.
I have a textbox and some labels inside the data template of bounded listbox.
When I click on any label the whole item is highlighted in blue, but when I click directly on a different textbox the selection does not change.
Is there a way to make the selection of the listbox change even when a textbox is clicked?
thanks
This is what I've exactly asked few days ago, see post: "WPF: Trigger SelectedIndex changed whilst clicking on any control within a ListBoxItem area"
basically there are few solutions, using code behind and XAML, but I've not verified latter approach yet
The reason is because the TextBox handles the click event in order to receive focus. There are a number of ways to handle this, including but not limited to:
stop the TextBox handling mouse events (which prevents the user from focussing it using the mouse)
use an eventhandler when the TextBox gains focus (or PreviewClick or similar), to select the parent ListItem
I use Silverlight 4.0 and have got problems with ComboBox control. I want to implement a popup menu which will show and hide itself without clicking mouse. It should show when I place cursor on its region - this prt works well. Then it should hide whenever mouse pointer is placed outside of its region for a while. I implemented it with MouseEnter and MouseLeave events. My problem is ComboBox - this control behaves weirdly, in my opinion. Normally I would expect it to raise MouseEnter event when I put the cursor on it and MouseLeave when I put the mouse cursor anywhere else. The real situation is different: Whenever I click the combobox, it opens and shows the list of options, and immediately sends LostFocus and MouseLeave events. So it seems like the control lost keyboard focus and mouse pointer has been moved out of its region, while actually the combobox list of optins is open and active and has keyboard focus in it.
So the question is how can I know in my program what is happening in comboboxes? In order to correctly hide my popup menu, I need to know when the list of options in a combobox is open or closed. I can't see any events for this or any other documentation. (Wanted behavior is: If a combobox is closed, I hide my popup menu based on the position of mouse cursor. If a combobox is open, I never hide my popup menu until user either selects something in the combobox, or closes the combobox.)
Also, if you have got a good experience with a third party combobox replacement, which looks and works similarly AND raises events I need, please let me know.
MSDN has two events listed for ComboBox that you might want to look at.
http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox_events(v=VS.95).aspx
DropDownClosed Occurs when the drop-down portion of the combo box closes.
DropDownOpened Occurs when the drop-down portion of the combo box opens.
I want to display a custom confirmation message box (ChildWindow) when the user selects a row in a DataGrid in Silverlight. The message box simply has 2 buttons, a yes and a no. When the user clicks No, I want to restore the previously selected item in the DataGrid. I have been able to accomplish all of that.
The problem is that when the message box appears and I click NO and I restore the previously selected item, the item that the user tried to select remains in the MouseOver visual state until I move the mouse over some other row.
Is there any known workaround for this unusual behaviour of the DataGrid, or is this perhaps a legitimate bug in the control? I have done my research and I have not found anything as yet.
Any help would be appreciated.
Thanks!
This is classic mouse enter/leave gotcha thats common in many areas of Silverlight and indeed in many other frameworks as well. The assumption is that that mouse in and out events will come in pairs but they don't when a something else hijacks the mouse events.
Thats is what is happening here the DataGridRow is simplisticly tracking mouse over using the standard mouse events. However when you show a child window while it is in the mouse over state not further mouse events go to the row. When you dismiss the childwindow the mouse is already outside the row so it still gets no events.
A possible workaround is to fiddle with the visual state of the row yourself before showing the child window:-
VisualStateManager.GotoState(someRow, "NormalSelected", false);
Not perfect but possible good enough.