Custom Add-In -  Programmatically Set Visibility of "Map Contents"

3466
8
Jump to solution
07-03-2012 08:52 AM
friskyweasel
New Contributor
When my custom add-in's toolbar icon is clicked, I would also like to display the "Map Contents" window. In short, I want to always be sure the "Map Contents" windows appears any time my custom add-in dialog appears.

Can anyone provide an example of how to do this? Thanks for your time!
0 Kudos
1 Solution

Accepted Solutions
KarenEllett
Occasional Contributor
Good!

I looked through the layout xml file.  You'll find it under C://inetpub/wwwroot/Apps/MyViewer/Config/Layouts.  You find the Layout you're using; Glass, for instance, and open that xml file in Visual Studio. 
If you haven't created your viewer yet, you can find it in the default builder folder; that's usually at C://inetpub/wwwroot/Builder/Templates/Default/Config/Layouts.

The attribute table is set up a little differently, looks like.  For instance, you can't use "SidePanel" because it doesn't open there, and there's no corresponding "BottomPanel". 

I'm pretty sure your container is FeatureDataGridContainer and your control is FeatureDataGrid.

I think you might be able to just set the visibility of the FeatuerDataGridContainer to visible when you launch the tool.

View solution in original post

0 Kudos
8 Replies
KarenEllett
Occasional Contributor
I did something similar, but in a behavior so that the ToC was open by default when the viewer launched.  You could probably modify it to work in the tool.  In the MyBehavior class I used the follwing code (you could probably add this in your dialog code)

#region Behavior Overrides
        protected override void OnAttached()
        {
            base.OnAttached();

            UIController.Instance.ShowSidePanel(null, "MapContentsTabItem", false);
        }
        #endregion

I then added a class called UIController.cs with the following code:

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Extensibility;


namespace ContentsBehavior.AddIns
{
    public sealed class UIController
    {

        static readonly UIController _instance = new UIController();

        public static UIController Instance
        {
            get { return _instance; }
        }

        private UIController() { }


        public void SetAppBusy(bool busy, string sMessage)
        {

            System.Windows.Application.Current.RootVisual.Dispatcher.BeginInvoke(
            delegate
            {

            });
        }

        /// <summary>
        /// show Silverlight Viewer's Side Panel
        /// </summary>
        public bool ShowSidePanel(TabItem tabItem, string sOrItemName, bool bForceVisible)
        {

            System.Windows.Controls.TabControl tab = MapApplication.Current.FindObjectInLayout("SidePanelContainer") as TabControl;
            if (tabItem == null)
            {
                tabItem = tab.FindName(sOrItemName) as TabItem;
            }

            if (tabItem != null)
            {
                tabItem.Visibility = Visibility.Visible;
                // Hide if already present
                if (tab.Visibility == Visibility.Visible && tabItem.IsSelected && !bForceVisible)
                {
                    VisualStateGroup vg = VisualStateManager.GetVisualStateGroups(tab)[0] as VisualStateGroup;
                    VisualState vs = vg.States[1] as VisualState;
                    System.Windows.Media.Animation.Storyboard sbHide = vs.Storyboard;
                    sbHide.Begin();
                }
                else if (tab.Visibility == Visibility.Visible)
                {
                    tab.SelectedItem = tabItem;
                }
                else
                {
                    VisualStateGroup vg = VisualStateManager.GetVisualStateGroups(tab)[0] as VisualStateGroup;
                    VisualState vs = vg.States[0] as VisualState;

                    System.Windows.Media.Animation.Storyboard sbShow = vs.Storyboard;
                    sbShow.Begin();
                    tab.SelectedItem = tabItem;
                }
                return true;
            }

            return false;
        }


    }
}


I should add that I used the AddressRouteFinder addin in the code gallery to learn how to do this, and a good deal of this code comes directly from theirs.  So kudos goes to them.
Hope this helps!
friskyweasel
New Contributor
Thanks so much Karen it worked like a charm.

Quick question - I would also like to implement the same logic for the built-in, default "Attributes Table" dialog window. Now that I have working logic, all I think I need is the "handle" name for that particular container and control. Just curious, in this line:

UIController.Instance.ShowSidePanel(null, "MapContentsTabItem", false);

How did you come to find out that the "Map Contents" window was referenced by the name: MapContentsTabItem?

Is there a link somewhere that has the control names?
0 Kudos
KarenEllett
Occasional Contributor
Good!

I looked through the layout xml file.  You'll find it under C://inetpub/wwwroot/Apps/MyViewer/Config/Layouts.  You find the Layout you're using; Glass, for instance, and open that xml file in Visual Studio. 
If you haven't created your viewer yet, you can find it in the default builder folder; that's usually at C://inetpub/wwwroot/Builder/Templates/Default/Config/Layouts.

The attribute table is set up a little differently, looks like.  For instance, you can't use "SidePanel" because it doesn't open there, and there's no corresponding "BottomPanel". 

I'm pretty sure your container is FeatureDataGridContainer and your control is FeatureDataGrid.

I think you might be able to just set the visibility of the FeatuerDataGridContainer to visible when you launch the tool.
0 Kudos
friskyweasel
New Contributor
Your latest reply was 100% on the mark, not to mention that it pointed me in the right direction right off the bat, as opposed to me having to stumble my way to it. Thanks so much - if I could give you another point I would! : )
0 Kudos
KarenEllett
Occasional Contributor
Glad I could help!!  I'm still doing my fair share of stumbling, so I'm just glad I could help you avoid some of it. 🙂
0 Kudos
BarraLoubna
New Contributor
Glad I could help!!  I'm still doing my fair share of stumbling, so I'm just glad I could help you avoid some of it. 🙂


Hello, thanks for your help and I wish if you can help me also.

I posted my problem here :

http://forums.arcgis.com/threads/61441-add_in-a-download-tool-to-Layer-Context-Menu.

if you have some idea ?

thank you.
0 Kudos
IvanGnevanov
New Contributor III
ardaiel,

Thank you again. It is a great idea, but seems it does not work properly for me.
It works only when I activate the behaviour, but each time I load an application the panel hides.

Do you have an idea why?
0 Kudos
KarenEllett
Occasional Contributor

I'm so sorry, I only just saw this... I never get notifications about replies!  By now you probably have already fixed this, but if you still have questions, let me know.  I can take a look at the code, there's a few different reasons it might be doing that.

0 Kudos