Change Active Map based on Active Ribbon

700
7
Jump to solution
12-11-2019 08:08 PM
SreenivasaRaoPigili
Occasional Contributor

Hi All,

    

By using ActiveMapViewChangedEvent subscribe method (ActiveMapViewChangedEvent ), i am able to change/activate my ribbon/tab based on the active map view.

Now we want to implement opposite communication. i.e whenever we change the ribbon/tab, the corresponding MapView has to get activate. 

I have tried to use ArcGIS.Desktop.Framework.Events.ActivePaneChangedEvent.Subscribe(OnActivePanChanged) and ActiveWindowChangedEvent.Subscribe(OnActiveWindowChanged) options. But these two methods are not getting fired when we change the ribbon/tab.

Appreciate your help on this. Thank you.

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Srinu,

 When debugging methods like OnUpdate, that are repetitively called in the background, you cannot use MessageBox.Show or any other method that will hang the OnUpdate function.  Using methods like

System.Diagnostics.Debug.WriteLine

as i did in my sample because these functions will not 'hang' the method and you can still see our output when looking at the Visual Studio output window.  Also you cannot set breakpoints in these types of methods for the same reason.  After reading your bullets 1 and 2 above, i wanted to note that you can use the ArcGIS Pro SDK Item templates to add buttons to your add-in.  Pro SDK item templates will stub out all code and daml you need.  See: install-arcgis-pro-sdk-for-net and ProGuide-Build-Your-First-Add-in for more details in case you are not aware of this.

I attached a sample project TabShowMappane.  Look at the code in the Module1 class and the two buttons (one for each tab).  You need a project that has two map panes: Map1 and Map2 as shown here and click on the "Tab Map 1" tab:

Not that the Map1 mapview is active.  Now click on the "Tab Map2" tab:

and see the active mapview change to Map2.

I hope this gets you started.

View solution in original post

7 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Srinu,

 Can you explain your desired workflow in a bit more detail?  Are these ribbons or tabs you are changing defined in your add-in?  There is sample code that manipulates which map views are activated from a dockpane, maybe that helps: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Framework/OpenMapViews

- Wolf

0 Kudos
SreenivasaRaoPigili
Occasional Contributor

Hi Wolf,

   Thank you for your response.

Yes all these ribbons are defined in my add-in, through config.daml. Also, Mapview are created through code. 

For ex, If “MapViewA” is tagged to “Ribbon A”, “MapViewB” is tagged to “RibbonB” etc.

Now requirement is :

If we make “RibbonA” active, then “MapViewA” has to get active automatically.

If RibbonB is active then MapViewB should become active etc etc.

Hope this clarifies your question. Please let me know, if you need any details further.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Srinu,

 Unfortunately i can't find any 'out-of-box' events in the API that will help you with this. As a possible workaround i think you can override one of your UI control's OnUpdate() methods in order to trigger your code to check if the matching map pane is being displayed.  Needless to say you have to implement this for one UI control on each tab.  I did a sample test on a button control: 

internal class Button1 : Button
{
    protected override void OnClick()
    {
    }

    protected override void OnUpdate()
    {
        System.Diagnostics.Debug.WriteLine("Add your logic here");
        base.OnUpdate();
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

OnUpdate was called as soon as the add-in was loaded (in my case i am using JIT loading - with a module 'autoLoad=false', so my code is not executed until i click on a button or other component of my add-in).

I hope this helps.

- Wolf

0 Kudos
SreenivasaRaoPigili
Occasional Contributor

Thank you Wolf for your time in analyzing this. I will use this approach.

0 Kudos
SreenivasaRaoPigili
Occasional Contributor

Hi Wolf,

    I have tried this option. Please find the observations below.

1. I have added this piece of code in my class file and inherited from ArcGIS Button.

2. This code is getting executed only when i clicked on the button.

3. Then OnUpdate() is executing infinitely.

<button id="Button1" caption="Button1" className="Button1" loadOnClick="true" smallImage="Images\xyz16.png" largeImage="Images\xyz32.png">
<tooltip heading="Button1">
Button1<disabledText />
</tooltip>
</button>

internal class Button1 : Button
{
/*
protected override void OnClick()
{
MessageBox.Show("Testing");
OnUpdate();
}*/

protected override void OnUpdate()
{
MessageBox.Show("Observing the ribbon loading event" + FrameworkApplication.ActiveTab);
base.OnUpdate();     //base.OnUpdate();  
}
}

Please let me know, if i am doing any wrong here.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Srinu,

 When debugging methods like OnUpdate, that are repetitively called in the background, you cannot use MessageBox.Show or any other method that will hang the OnUpdate function.  Using methods like

System.Diagnostics.Debug.WriteLine

as i did in my sample because these functions will not 'hang' the method and you can still see our output when looking at the Visual Studio output window.  Also you cannot set breakpoints in these types of methods for the same reason.  After reading your bullets 1 and 2 above, i wanted to note that you can use the ArcGIS Pro SDK Item templates to add buttons to your add-in.  Pro SDK item templates will stub out all code and daml you need.  See: install-arcgis-pro-sdk-for-net and ProGuide-Build-Your-First-Add-in for more details in case you are not aware of this.

I attached a sample project TabShowMappane.  Look at the code in the Module1 class and the two buttons (one for each tab).  You need a project that has two map panes: Map1 and Map2 as shown here and click on the "Tab Map 1" tab:

Not that the Map1 mapview is active.  Now click on the "Tab Map2" tab:

and see the active mapview change to Map2.

I hope this gets you started.

SreenivasaRaoPigili
Occasional Contributor

Thank you Wolf. This helped me to start. Appreciate your help on this resolution and clarification.

0 Kudos