I have written a behavior that expands the Map Contents on loadAlso play around with the settings forTools -> Configure Controls -> Map Contents -> Check Expand Layers on AddBehavior code:
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
using System.Windows.Media.Animation;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Extensibility;
namespace MyBehaviour.Panels
{
[Export(typeof(Behavior<Map>))]
[DisplayName("Show Hide Map Content Panel")]
[Category("Behaviors")]
[Description("Display Map Content Panel on load")]
public class MapContentBehavior : Behavior<Map>
{
#region Behavior Overrides
protected override void OnAttached()
{
base.OnAttached();
MapApplication.Current.Map.Loaded += Map_Loaded;
}
protected override void OnDetaching()
{
MapApplication.Current.Map.Loaded -= Map_Loaded;
}
#endregion
#region Events
void Map_Loaded(object sender, RoutedEventArgs e)
{
// Find SidePanel
TabControl sidePanel = MapApplication.Current.FindObjectInLayout("SidePanelContainer") as TabControl;
if (sidePanel != null)
{
TabItem tab = null;
int customControlPanelIndex = -1;
// Get the index of the tab in the side panel that contains our control
for (int i = 0; i < sidePanel.Items.Count; i++)
{
tab = sidePanel.Items as TabItem;
if (tab.Name == "MapContentsTabItem")
{
customControlPanelIndex = i;
break;
}
}
Storyboard storyBoard;
// Check whether the control needs to be shown or hidden
if (sidePanel.SelectedIndex != customControlPanelIndex || sidePanel.Visibility == Visibility.Collapsed)
{
// Update the side panel's selected index to set the tab containing the control to be the selected one.
sidePanel.SelectedIndex = customControlPanelIndex;
// Check whether the side panel is visible at all. If not, it needs to be shown
if (sidePanel.Visibility == Visibility.Collapsed)
{
// Check whether the side panel has a visual state called Show. If so, we'll show the side
// panel by invoking the storyboard from this state.
storyBoard = VisualStateManagerHelper.FindVisualStateStoryboard(sidePanel, null, "Show", true);
if (storyBoard != null)
storyBoard.Begin();
else // The side panel does not have a Show state, so set the panel's visibility directly
sidePanel.Visibility = Visibility.Visible;
}
}
else
{
// The toggle button is being clicked when the control is already visible. So the click should hide it.
// Check whether the side panel has a visual state called Hide. If so, we'll hide the side
// panel by invoking the storyboard from this state.
storyBoard = VisualStateManagerHelper.FindVisualStateStoryboard(sidePanel, null, "Hide", true);
if (storyBoard != null)
storyBoard.Begin();
else // The side panel does not have a Hide state, so set the panel's visibility directly
sidePanel.Visibility = Visibility.Collapsed;
}
}
}
#endregion
}
}