I have a User Control with an image in it and when the user clicks the image I use a popup to display a record card. I set StaysOpen="False" and all works perfectly through my application, except when I host it in a ListBox. In this case the Popup refuses to recognise a click away from it. Is there an issue with raising a popup from a ListBoxItem or are there other ways around this?
Maybe, opening Popup using Interactivity commands instead of using a Button could be the issue.
Interactivity is not doing the mouse capture and keyboard focus actions. So, Popup will not have a proper mouse capture reference by using Interactivity commands.
I did find the answer in the end and t was my mistake. The action to raise the popup was done on Mouse Down and the popup was opening and then closing on the mouse up cation. All I did was to change it to Mouse Up and it was fine. Thank you for your answer anyway.
Related
I have a WPF ListBox, where the items are styled to be Buttons. I've used gong-wpf-dragdrop to very easily implement drag-and-drop, so I can reorder the listitems. However, I would now like to be able to left-click on one of the buttons to launch an edit action, but the MouseLeftButtonUp event on the ListBox seems to be being swallowed by the drag-and-drop operation. (I'm using EventToCommand from MVVM Light to hook everything up).
Changing the ListBox to respond to MouseRightButtonUp works fine (so I can drag-and-drop with the left mouse button, and launch the edit action with the right mouse button), but I would rather keep the right mouse button for a context menu.
I also tried using MouseDoubleClick, but although that launched the edit action, it always opened the first item in the list for editing, and moved the listitem that was double-clicked to the top of the list - very confusing for everyone concerned!
Any thoughts on how to approach this?
If i understand you correctly, you don't want to drag&drop if you click the button. One way to do that is to hook up with the PreviewMouseLeftButtonDown of the button. Initiate you edit action in the eventhandler and set e.Handled=true. This way the MouseLeftButtonDown will not arrive at the listbox and no drag&drop operation will be initiated. One disadvantage is that the button will react on the mousedown instead of the mouseup (so it's like ClickMode=Press).
Regards,
Rob
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'm developing a Microsoft Word TaskPane containing a WPF ElementHost. The hosted WPF uses a Popup that is intended to behave as a ComboBox's does. I believe you can reproduce my problem like this:
popup.IsOpen = true;
popup.StaysOpen = false;
Mouse.Capture(ancestor_of_popup, CaptureMode.SubTree);
When a region of the Popup lies outside the bounds of the TaskPane, click the mouse in that region. The entire TaskPane loses keyboard focus to Word's main window, but retains mouse capture. At this point, you can use the Popup with a mouse while typing on the keyboard edits your document!
If the TaskPane loses keyboard focus then the Popup should close, but then any control in the region of a Popup that lies outside the bounds of the TaskPane becomes unusable. Any ideas?
This looks like a similar problem to Popups in XBAP stop receiving anything but mouse events after losing focus?.
Apparently there is a known bug with focus in WPF popup controls, although that may be specific to XBAP (you didn't specify if this was a WPF desktop or browser application).
I am hosting windowsforms control in WPF popup. Problems below:
If i make StaysOpen=False i can't interact with winform control. StaysOpen to false is required because when clicked outsidet the Popup region, it should close.
if i make StaysOpen=True i can interact with winform control but when i click outside the area of popup, it is not getting closed.
I tried setting StaysOpen=true in MouseEnter of popup and StaysOpen=False in MouseLeave, but MouseLeave fires as and when mouse is over winform control resulting in unexpected behaviour.
I even tried IsMouseCaptureWithin property of popup and found it does not work with winforms (i guess its a bug in framework).
Another problem, i was trying to close popup when root main form (which is windows form) is deactivated (pressed Alt+Tab), but this event (deactivate) is fired even when i enter into one of the controls in windowshostControl in popup.
Desired Behaviour:
should be able to host and interact with winform control in wpf popup.
on clicking on outside the area of popup, popup should close.
Appreciate any inputs.
Thanks.
I've had many problems with the defacto-standard popups in WPF, because they are in fact a new window with their own handle. This means if you drag your application around the screen, the popup stays put (it doesn't move with your window). It also means your popup has some strange behaviors and doesn't interact with your application in ways other controls normally do.
I've created 2 decorator classes to address this problem:
PopupDecorator.cs and
TimeoutPopupDecorator.cs
It's pretty simple to use:
Add a namespace declaration for the new popup classes. i.e.
xmlns:dday_wpf="clr-namespace:DDay.WPF"
Surround the area you want the popup to be able to be displayed with the decorator. i.e.
<dday_wpf:PopupDecorator x:Name="popup">
<dday_wpf:PopupDecorator.Popup>
... contents of popup go here ...
</dday_wpf:PopupDecorator.Popup>
... contents of panel go here ...
</dday_wpf:PopupDecorator>
It works pretty much identically to a normal Popup from that moment on.
This may not solve all your problems, but hopefully it helps.
This sounds a bit like my problem launching a modeless winform control from a WPF form.
Check out my question Why is my WPF textbox "kinda" readonly?.
The just being, based on what Doug said about popups being a window with its own handle, makes this applicable.
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.