I am pretty familiar with Windows Forms in ArcGIS but WPF, which I'm just starting to tinker with, seems to be a different animal. I've created an ArcMap add-in with a button that displays a Window with some controls on it and would like to display it as a modal dialog and have it behave like other dialogs in ArcMap. That is, it should:
- Initially display centered in the middle of the ArcMap window
- Block the ArcMap main thread from continuing until the window is closed
- Not allow the ArcMap application's window to take the focus
- Not have its own task bar button or show up in the alt-tab list
- Always draw on top of the ArcMap window
I've gotten 1 and 2 taken care of, but the rest I haven't figured out yet.
Anyone already tackled this?
Related: How stable is WPF in Arcmap?
Best Answer
The key to proper parenting of WPF windows within a non-WPF application is to use the WindowInteropHelper class.
Suppose you have a
WpfWindow
class which is a WPF window (derives fromWindow
):The code snippet above also shows how to hide the window from taskbar, which is a straightforward property of the
Window
class.It also has the WindowStartupLocation emum property, but its
CenterOwner
option does not work when the owner is not a WPF window. You need to center the window manually instead. I will not reiterate here and rather refer you to this article which gives a detailed description: Centering WPF Windows with WPF and Non-WPF Owner Windows.