Which layer triggered the VisibilityChanged event?

860
2
06-25-2013 09:53 PM
ChristianAlfons1
New Contributor
Hello!

Consider the following code sample, found here and here.

private ILayerEvents_Event pLayerEvents;

void mActiveViewEvents_ItemAdded(object Item)
{
    if (Item is ILayerEvents_Event)            
    {
        pLayerEvents = Item as ILayerEvents_Event;
        pLayerEvents.VisibilityChanged += new ILayerEvents_VisibilityChangedEventHandler(pLayerEvents_VisibilityChanged);
    }
}

void pLayerEvents_VisibilityChanged(bool currentState)
{
    //do something here
}


How can I find out which layer triggered the VisibilityChanged event? The pLayerEvents_VisibilityChanged method only receives the visibility state.


Thanks.
0 Kudos
2 Replies
ChristianAlfons1
New Contributor
No one? Seems like such a simple thing, I just don't know where to look.
0 Kudos
RichardFairhurst
MVP Honored Contributor
No one? Seems like such a simple thing, I just don't know where to look.


From the comments in one of the links you provided, this is a very weak interface feature that requires a lot of custom code to even set it up.  It won't detect if the layer you are interested in is made part of a Group Layer that has a different visible state and once it is made part of the group layer it is possible its events will cease operating (that is what the comments meant when they talked about needing to design their own recursive methods to handle group layers).  There seems to be no interface that directly does what you want (which is typical for poorly documented ArcObjects interfaces, especially methods that require recursive handling to really cover all possible effects within the TOC or ActiveView).

If you must know exactly what layer changed its visible state at the moment it changes, then you need an array, list, structure or other storage class level variable to track the last known visible state of the layers you wish to track and the run a comparison with the current state when you detect a visiblechanged event and then do the thing you are trying to do.  However, that class variable may not be necessary if all you are trying to do is make sure a particular layer or set of layers stays visible and are not made part of a group layer.  So describe how you envisioned this event fitting in to your application workflow and your real objectives to get better help.
0 Kudos