AnsweredAssumed Answered

ActiveMapViewChangedEvent

Question asked by bulla_b on Apr 12, 2018
Latest reply on Apr 12, 2018 by bulla_b

Hi,

 

I'm trying to detect when the current MapView changes, so I can then activate/deactivate a button on a toolbar based on layers in the active map.

 

But when I click on (for example) the 'Catalog' tab, the ActiveMapViewChangedEvent fires and I get a NullReferenceException.  As a workaround, I just catch the exception and disable the tool.

 

Is there a better way to determine if the user is no longer on a 'MapView' tab??

 

            ActiveMapViewChangedEvent.Subscribe((args) =>
            {
                try
                {
                    var lyr = MapView.Active.Map.FindLayers("SDEDB1.GISADMIN.ADDR_Durham").FirstOrDefault();
                    if (lyr == null)
                        FrameworkApplication.State.Deactivate(StateID);
                    else
                        FrameworkApplication.State.Activate(StateID);
                }
                catch (NullReferenceException)
                {
                    FrameworkApplication.State.Deactivate(StateID);
                }               
            });

Outcomes