Get reference to view model from child control class

520
2
Jump to solution
07-28-2022 04:55 PM
PeteVitt
Occasional Contributor III

Hi – I’m working with the ArcGIS Pro sdk 3.0 and  have a DockPane view model that contains a MapTool. I'd like to get a reference to the DockPane View Model from the MapTool class code to set some properties back on the DockPane. In the code below I’m getting an error ‘DockPane is a type, which is not valid in the given context’.  Is there a way I can correct this? I’ve seen this work getting a reference to an EmbeddableControl ViewModel in the SequentialNumberTool Sample (https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/master/Editing/SequentialNumberTool/Se...)

using ArcGIS.Desktop.Framework.Contracts;

internal class LandscapeSelectionTool : MapTool

    {

Dockpane1ViewModel _vm;

protected override Task OnToolActivateAsync(bool active)

        {

            _vm = DockPane as Dockpane1ViewModel;//Error occurs here

            return base.OnToolActivateAsync(active);

        }

}

Thanks

Pete

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

 

"Dockpane" is a type, not a Dockpane instance which is what u are after.

cast the returned value from FrameworkApplication.DockPaneManager.Find("dockpane_id") to your dockpane view model class. For instance:

 

_vm = FrameworkApplication.DockPaneManager.Find(
                 "ProAppModule1_Dockpane1") as Dockpane1ViewModel;

 

This is, essentially, the same thing the auto-generated code for the Dockpane item template is doing when it consrtucts its "default" Show method (to activate the dockpane in the first place).

 

/// <summary>
/// Show the DockPane.
/// </summary>
internal static void Show()
{
  DockPane pane = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
  if (pane == null)
    return;

  pane.Activate();
}

 

View solution in original post

0 Kudos
2 Replies
CharlesMacleod
Esri Regular Contributor

 

"Dockpane" is a type, not a Dockpane instance which is what u are after.

cast the returned value from FrameworkApplication.DockPaneManager.Find("dockpane_id") to your dockpane view model class. For instance:

 

_vm = FrameworkApplication.DockPaneManager.Find(
                 "ProAppModule1_Dockpane1") as Dockpane1ViewModel;

 

This is, essentially, the same thing the auto-generated code for the Dockpane item template is doing when it consrtucts its "default" Show method (to activate the dockpane in the first place).

 

/// <summary>
/// Show the DockPane.
/// </summary>
internal static void Show()
{
  DockPane pane = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
  if (pane == null)
    return;

  pane.Activate();
}

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

I suggest you to use Esri pattern EmbeddableControl. It has tool - dockpane connection realized already. How to use it you can found here:

ProGuide Using Embeddable Controls · Esri/arcgis-pro-sdk Wiki · GitHub

0 Kudos