4

I'm creating a dockable window add-in that requires the Active View to be the Data View.

I would like to disable my window when the user enters Layout View, but I've been unable to find an event that is triggered when the View changes.

I've attempted to us the "ActiveViewEvents" but none of them go off when switching views. And I know I can check if I'm in Layout view via:

IMxDocument doc = ArcMap.Document as IMxDocument;
if (doc.ActiveView is IPageLayout){/*disable window*/}
else {/*enable window*/}

but I'm at a loss on where to put this sort of check.

What event can I utilize to check when the users changes the View?

I want this event to be fired any time the user changes the view, and I do not want to put this check on every control.

enter image description here and/or enter image description here

5
  • Can the add-in XML be used to set the dockable window enabled/disabled state the same way it can for toolbar buttons? I've done something similar in the past disabling/enabling buttons based on Data View or Layout View, but never made a dockable window so unsure if it works the same. If it does (or might) I'll have a dig around and see if I can find my old code
    – Midavalo
    Commented Mar 27, 2017 at 21:01
  • You could use the ViewRefreshed event of IActiveViewEvents resources.arcgis.com/en/help/arcobjects-net/componenthelp/… (called frequently but that should be ok if you're only testing the view just to enable/disable a form) or FocusMapChanged of same interface might work resources.arcgis.com/en/help/arcobjects-net/componenthelp/… how are you wiring the event? It sounds like you haven't wired the event properly. Commented Mar 27, 2017 at 22:44
  • I did try FocusMapChanged, and it didn't go off when either of the Layout View buttons were pressed, and I thought I had ViewRefreshed going off too, but my breakpoint wasn't being hit. I'm in VS2015 and I used the "Add Snippet > ArcObjects > Mapping > Add Event Wiring for All IActiveViewEvents" ViewRefreshed will work. @MichaelMiles-Stimson if you make an answer I will accept it. Commented Mar 28, 2017 at 12:38
  • If you use a button to open the dockable window, you could add the code to check whether the map is in Layout View or Data View in the button's OnUpdate sub and set Enabled = False if the map is in Layout View. This will disable the button. And if the dockable window is already open you can put whatever code you want to disable the window functionality in there as well, for example dockableWindow.Show(False). Commented Mar 28, 2017 at 13:10
  • John, if it's worked for you after reading the comment please answer your own question (yes, it's allowed and encouraged) with some of your code preferably... I'll come back later to upvote (or comment). Commented Mar 28, 2017 at 22:29

1 Answer 1

3

Subscribing to view change event:

((ESRI.ArcGIS.ArcMapUI.IDocumentEvents_Event)ArcMap.Document).ActiveViewChanged += OnActiveViewChanged;

Handling view change event:

private void OnActiveViewChanged()
{
    if (((IMxDocument)ArcMap.Document).ActiveView is ESRI.ArcGIS.Carto.IPageLayout)
    {
        System.Diagnostics.Debug.Print("PAGE LAYOUT");
    }
    else
    {
        System.Diagnostics.Debug.Print("DATA LAYOUT");
    }
}
1
  • This looks to be the more reliable solution over OnActiveViewEventsViewRefreshed. It seems to be called less frequently. Commented Mar 29, 2017 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.