I am working on a tool that uses a dockpane to display results from features in a box from a maptool. I actually have already created this tool with a windows form and it works really well except for one issue that I don't think can be resolved, so I'm looking at the dockpane, which I believe is the only other way to get a form in Pro. However, I open the dockpane, then draw the box with the maptool, and when I call a function in the dockpane a null reference exception is returned. The data that I'm passing to the dockpane is not null, and I even tested it without passing any data and the dockpane still comes back null.
I am using Esri sample "MapToolIdentifyWithDockpane" as a reference, and I have everything set up the same way as in that sample. The sample works, mine does not.
I have this in the config.daml for the dockpane:
<dockPanes>
<dockPane id="CustomIDDockPane_dpIDTools" caption="dpIDTools" className="dpIDToolsViewModel" dock="float" dockWith="esri_core_projectDockPane">
<content className="dpIDToolsView" />
</dockPane>
</dockPanes>
This is what I have in Module1 to define the dockpane:
internal class Module1 : Module
{
private static Module1 _this = null;
private static dpIDToolsViewModel _dpIDToolsVM = null;
public static Module1 Current
{
get
{
return _this ?? (_this = (Module1)FrameworkApplication.FindModule("CustomIDDockPane_Module"));
}
}
internal static dpIDToolsViewModel dpIDToolsVM { get; set; }
}
I call this from the tool, this is where the error occurs:
Module1.dpIDToolsVM.LoadIDResults(mapLayerNames, feat);
This is the code in the viewmodel that the above line is calling:
internal void LoadIDResults(List<string> layerNames, Dictionary<BasicFeatureLayer, List<long>> featureLayerList)
{
List<IDFeaturesInLayer> iList = new List<IDFeaturesInLayer>();
foreach (KeyValuePair<BasicFeatureLayer, List<long>> b in featureLayerList)
{
IDFeaturesInLayer i = new IDFeaturesInLayer();
i.Value = b.Key;
i.Text = b.Key.ToString();
iList.Add(i);
}
}
Thank you in advance for any assistance offered.
Jeff
Solved! Go to Solution.
I created a new AddIn project ProAppModule1, then added two items: a Dockpane and a MapTool.
I added code to the OnSketchCompleteAsync in MapTool1.cs using the id from the daml file (ProAppModule1_Dockpane1):
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
// added this code:
var dockPaneID = "ProAppModule1_Dockpane1";
var paneVm = FrameworkApplication.DockPaneManager.Find(dockPaneID)
as Dockpane1ViewModel;
if (paneVm != null)
{
paneVm.Heading = Environment.TickCount.ToString();
}
return base.OnSketchCompleteAsync(geometry);
}
I ran it, clicked the Maptool1 button, then clicked on the map twice:
Note that I made no changes to the Module1.cs or Dockpane1ViewModel.cs.
The only change was to MapTool1.cs.
I created a new AddIn project ProAppModule1, then added two items: a Dockpane and a MapTool.
I added code to the OnSketchCompleteAsync in MapTool1.cs using the id from the daml file (ProAppModule1_Dockpane1):
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
// added this code:
var dockPaneID = "ProAppModule1_Dockpane1";
var paneVm = FrameworkApplication.DockPaneManager.Find(dockPaneID)
as Dockpane1ViewModel;
if (paneVm != null)
{
paneVm.Heading = Environment.TickCount.ToString();
}
return base.OnSketchCompleteAsync(geometry);
}
I ran it, clicked the Maptool1 button, then clicked on the map twice:
Note that I made no changes to the Module1.cs or Dockpane1ViewModel.cs.
The only change was to MapTool1.cs.
Thanks Kirk, that worked. The sample that I was looking at didn't have it defined that way, it was using the definition in Module1. This was much simpler. I appreciate you looking at this, this will get me going on to the next challenge in this app.
Thanks,
Jeff
What they are suggesting would scale a better as your code evolves. When things get complicated its often better to have the each component talk to the module instead of talking directly to each other.
I'm going to move forward with this one, as it's a fairly simple app, but definitely will continue trying to get the other method to work. This new api is definitely a learning curve but I'm getting a lot more used to it.