How do you instantiate dockpane programattically?

233
1
04-16-2020 01:46 PM
JamesGough
New Contributor III

I have an add-in with a button and a couple of mapTools in a group, as well as a dockpane (The buttons are not in the dockpane). When the button is pressed it runs a GPService, and when that service finishes, the results are displayed in the dockpane.

Right now, this is working, but only if you manually open the dockpane before running the tool (by clicking the ShowButton).

If the dockpane is not opened manually then FrameworkApplication.DockPaneManager.Find() returns null since the dockframe instance has not been created.. 

I have tried calling the Show() method on the viewmodel (since this gets called when you click the button), however this does not seem to actually create the dockpane instance.

I am also using the FrameworkApplication.DockPaneManager.IsDockPaneCreated() method, but it explicitly says that  "This function will not create the dock pane if it does not exist."

I can't find anywhere where it says how to create this instance. I see in the documentation where it says:

Dock panes are singletons: there is never more than one instance of a particular dock pane and once created, they are not destroyed until the application shuts down. Use Find to access a specific dock pane.

So how can you actually create that instance if it does not exist?

Tags (1)
1 Reply
Mira
by
New Contributor

For everyone coming here at a later point:  I had a similar problem, where a built-in dockpane wasn’t being instantiated with the DockPaneManager.Find(…) method.
 For me the solution was to find and activate the built-in Dockpane on the UI thread like so:            

Application.Current.Dispatcher.Invoke(() =>

           {
           var dockPane = FrameworkApplication.DockPaneManager.Find("esri_editing_CreateFeaturesDockPane");
               dockPane.Activate();
           });