Select to view content in your preferred language

ActiveMapViewChanged event fires twice

1478
2
Jump to solution
02-27-2020 04:20 AM
Sai_PhaneendraPoludasu2
Occasional Contributor

I am working with ActiveMapViewChanged event as shown in the code snippet.

private void SubscribeMapEvents()
{
   ...
   ActiveMapViewChangedEvent.Subscribe(UpdateUIElements);
}

private void UpdateUIElements(ActiveMapViewChangedEventArgs obj)
{
   if (obj.IncomingView != null){
      ReInitializeUIElements();
   }
   else
   {
      ResetUIElements();
   }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Idea is to 

  • update the UI elements with the information from MapView when it changes and
  • reset to initial state when there is no map view.

The event triggers correctly when there is no map with IncomingView value as null, and when it updates the event is triggered with active map view's instance in the IncomingView parameter.  

Whereas, when I open an attribute table from Table of contents with an active map, this event is triggered twice.

  • First time with IncomingView as null and
  • the second time with the active map view's instance.

This behavior is causing an unwanted reset of the controls even when there is an active map present. 

0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi,

I would suggest that you should use ActivePaneChangedEvent instead. The type of pane returned when the Active Pane changes will tell you if it is a Map Pane or a Table. It will be MapPaneViewModel for an Active Map or TablePaneViewModel for a Table.  Code snippet:

//Subscribe to event
ArcGIS.Desktop.Framework.Events.ActivePaneChangedEvent.Subscribe(OnActivePaneChanged);

private void OnActivePaneChanged(PaneEventArgs obj)
{
   if (obj.IncomingPane != null)
   {
      System.Diagnostics.Debug.WriteLine($"Debug Message. GetTypeName: {obj.IncomingPane.GetType().Name}");
        
   }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

A little background on the behavior you are seeing with ActiveMapViewChanged event -

When you display the attribute table of a feature layer in the Active map, the IncomingView is first null (which is correct).
The attribute table pane then becomes the active pane. But when the attribute table pane is active, the TOC that lists the layers needs to know the “context” of which map it needs to use.
So the Attribute table pane that is currently active, “impersonates” the Map Pane. Hence the event gets triggered again and the Incoming View is now the “Map” associated with the attribute table.

Thanks

Uma

View solution in original post

2 Replies
UmaHarano
Esri Regular Contributor

Hi,

I would suggest that you should use ActivePaneChangedEvent instead. The type of pane returned when the Active Pane changes will tell you if it is a Map Pane or a Table. It will be MapPaneViewModel for an Active Map or TablePaneViewModel for a Table.  Code snippet:

//Subscribe to event
ArcGIS.Desktop.Framework.Events.ActivePaneChangedEvent.Subscribe(OnActivePaneChanged);

private void OnActivePaneChanged(PaneEventArgs obj)
{
   if (obj.IncomingPane != null)
   {
      System.Diagnostics.Debug.WriteLine($"Debug Message. GetTypeName: {obj.IncomingPane.GetType().Name}");
        
   }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

A little background on the behavior you are seeing with ActiveMapViewChanged event -

When you display the attribute table of a feature layer in the Active map, the IncomingView is first null (which is correct).
The attribute table pane then becomes the active pane. But when the attribute table pane is active, the TOC that lists the layers needs to know the “context” of which map it needs to use.
So the Attribute table pane that is currently active, “impersonates” the Map Pane. Hence the event gets triggered again and the Incoming View is now the “Map” associated with the attribute table.

Thanks

Uma

Sai_PhaneendraPoludasu2
Occasional Contributor

Thanks for the explanation of ActiveMapViewChanged event.

ActivePaneChanged event helps resolve the issue. Cheers!

0 Kudos