Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

  1. Initially display centered in the middle of the ArcMap window
  2. Block the ArcMap main thread from continuing until the window is closed
  3. Not allow the ArcMap application's window to take the focus
  4. Not have its own task bar button or show up in the alt-tab list
  5. 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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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 from Window):

    private void ShowWpfWindowModal()
    {
        var parentHandle = new IntPtr(_app.hWnd); // the ArcMap window handle

        var wpfWindow = new WpfWindow(); // the WPF window instance
        var helper = new WindowInteropHelper(wpfWindow);
        helper.Owner = parentHandle;

        wpfWindow.ShowInTaskbar = false; // hide from taskbar and alt-tab list

        wpfWindow.ShowDialog();
    }

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.

share|improve this answer
    
Thanks Petr, this works perfectly! –  blah238 Jul 10 '12 at 17:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.