I'm developing a VS-Package that shows a WPF window when a MenuCommand is invoked.
inside this WPF window I have a listBox, which is focused immediatly when the window is loaded.
when I show the window via myWindow.ShowDialog(), the arrow up/down key work as expected as I navigate through the listbox items.
However, when I show the window via myWindow.Show(), the listbox gains focus but the keyboard navigation inside the listbox is NOT WORKING, and the PreviewKeyDown event is not firing.
(instead, the caret inside VS editor is moving).
Please help.
Use Microsoft.VisualStudio.PlatformUI.DialogWindow class as the base class for your modal dialog. This should ensure proper keyboard accelerator handling as well as keeping the dialog consistent with the styling of the existing VS dialogs.
Related
I'm developing a custom control which has a button that opens a popup.
When that popup contains another instance of my custom control (which also has a button that opens another popup, e.g. a calendar) some problems occur.
The second (nested) popup won't act as suspected. Clicks don't work, won't close, when parent popup is closed.
Are there any specific best practices when using nested popups?
I had the same issue. We have a custom DropDownSubsetSelector control in our wpf controls library. This control has a Popup in its control template with StaysOpen="False". Today I had to put this control on a custom view that is located inside wpf's Popup control with StaysOpen="False" and was wondered of this unexpected nested Popups behaviour. My workaround for this issue was to inspect Microsoft's source code of a classical ComboBox control. You can find it here Combobox Source. As you can see its behaviour on a Popup control is exactly the same you expect from Popup being located on another Popup, and it's template has Popup inside (dropdown for selectable Items).
You must subscribe to events MouseDownEvent and LostMouseCaptureEvent and deal with mouse capturing for proper handling of MouseDownEvent outside of Popup control's area. Inspect and just copy some source code for your nested ExtendedPopup. You can inherit it from classical Popup.
Hi I have a WPF application with various UserControls that contain key functionality. I want to be able to show say a FileManager UserControl in a tab on the main application, or have a dialog pop up when required, that contains the same UserControl.
It seemed like a good idea to create a modal Window and set its Content to the FileManager Usercontrol. But when I am finished with it, I am not sure how to close the containing Window, using a button on the UserControl. Is there an elegant way of doing this without having to store a reference to the Window in the UserControl?
Thanks for any advice!
Create an Event which is called when the respective button on the user control is clicked. That way, the containing control can react to the event in the appropriate manner. For example, a dialog could just close itself.
Is closing a window something that is integral to the functionality of the control in all the contexts where the control is hosted? E.g Does closing a window apply to the case where the control is hosted in a tab of the main app?
If not then you might be better off separating window closing code out of the UserControl in into the window/dialog that is hosting it - using events or whatever to tie the two together.
I'm trying to create a custom UserControl that will mimic auto-complete as it works within Intellisense using WPF. I'm using a TextBox and a Popup containing a ListBox within my control.
I want to be able to keep keyboard focus set on the TextBox irrespective of whether or not the auto-completion popup is open so that a user can continue typing whilst simultaneously using up/down controls or the mouse to select elements in the popup to autocomplete the text. Is there any way this can be done in WPF?
Check out my article on CodeProject, it addresses the issue of the popup specifically.
A Reusable WPF Autocomplete TextBox
I have a TreeView control in a Windows application. I am opening another window from the TreeView click (Single Click) event (in tabbed environment, so all windows will appear as a tab in Visual Studio). I want to set focus to one control of the new window.
The problem is that, I am able to set the focus on the double click event of the TreeView. But same doesn't seem to be working with the TreeView single-click event.
Any workarounds?
Have you tried doing this in MouseUp instead? If that fails, there's always an easy (but disgusting) solution when it comes to UI issues like this: start a timer (with a running time of 10 ms or so) that will set the focus when it fires.
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.