'Map Contents' always visible at Silverlight Viewer page load

2117
3
12-05-2012 04:58 AM
JasonCadenhead
New Contributor
Is there a way to show the map contents within the map when the silverlight viewer page loads?  We want it to be always visible rather than asking our user to click the 'Map Content' to see the legend. 

Thanks!
0 Kudos
3 Replies
JasonCadenhead
New Contributor
Just to note I did come accross steps for editing the DefaultLayout.xaml file for ArcGIS for Sharepoint 2.1 to enable the map contents control (legend) within the Map Web Part to appear when the sharepoint page loads.

Does anyone know if there are steps out there for editing the DefaultLayout.xaml filie for ArcGIS for Silverlight 3.0?

Thanks!!!
0 Kudos
JasonCadenhead
New Contributor
From another thread I found that if you create a behavior (new project) within your web solution in Visual Studio and create two classes in your behavior addin, MyBehavior.cs and UIController.cs then the Map Contents will load up on the Silverlight Viewer startup. Here's the code:


MyBehavior.cs
-------------------------------------------------------------------------

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 System.Windows.Interactivity;
using System.ComponentModel.Composition;
using System.ComponentModel;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Extensibility;

namespace ContentsBehavior.AddIns
{
[Export(typeof(Behavior<Map>))]
[DisplayName("Open Table of Contents by Default")]
[ESRI.ArcGIS.Client.Extensibility.Category("Custom Tool")]
public class MyBehavior : Behavior<Map>
{

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

System.Windows.Controls.TabControl tab = MapApplication.Current.FindObjectInLayout("SidePanelContainer") as TabControl;
System.Windows.Controls.TabItem tabItem = MapApplication.Current.FindObjectInLayout("MapContentsTabItem") as TabItem;
tab.SelectedItem = tabItem;
tab.Visibility = Visibility.Visible;
tabItem.Visibility = Visibility.Visible;
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;

}
#endregion
}
}



UiController.cs
---------------------------------------------------------------------------------------------
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;
}


}
}
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Seems to be a SL viewer question.
Better to post it on the ArcGIS Viewer for Silverlight forum.
0 Kudos