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
Solved! Go to Solution.
"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();
}
"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();
}
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