<sdk:TabItem Header="Layers" Name="LayersTab" Margin="0,0,0,0">
<Grid>
<esri:Legend LayerItemsMode="Tree" x:Name="MyLegend" Map="{Binding ElementName=Map}"
LegendItemTemplate="{x:Null}" Refreshed="Legend_Refreshed"
LayerIDs="USAID_Layers" ShowOnlyVisibleLayers="false">
<esri:Legend.LayerTemplate>
<DataTemplate>
<!--Layer Item-->
<StackPanel x:Name="checkBoxName" Orientation="Horizontal">
<!-- Two overlapping checkboxes, the second checkbox is grayed when the layer is not visible-->
<Grid VerticalAlignment="Center">
<CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay}" />
<CheckBox IsChecked="{Binding IsEnabled}" IsEnabled="{Binding IsVisible}" IsHitTestVisible="False" />
</Grid>
<TextBlock Text="{Binding Label}" Tag="{Binding SubLayerID}" VerticalAlignment="Center" Margin="2,0,0,0" MouseLeftButtonDown="ClickOnLayerName" />
</StackPanel>
</DataTemplate>
</esri:Legend.LayerTemplate>
</esri:Legend>
</Grid>
</sdk:TabItem>
<sdk:TabItem Header="Legend" Name="LegendTab">
<Grid>
<esri:Legend Map="{Binding ElementName=Map}"
LayerItemsMode="Tree"
LayerIDs="USAID_Layers"
ShowOnlyVisibleLayers="True">
</esri:Legend>
</Grid>
</sdk:TabItem>
What I was asked is :
1. Remove the root element usaid_layers so it will show more data to the left
2. shrink the spaces from one layerItem to another in the legend tab.
Hi Dominique,
As to issue #1, I thought to do it in Legend.Refreshed event but I didn't know how to catch the root element in order to remove it.
I need to remove it, not to collapse it.
As to issue #2, I will check it. Do you have a sample of changing LegendItemTemplate ? I looked at your wonderful site (http://broux.dominique.free.fr/Silverlight/InteractiveSDK/Default.htm#LegendTOC) but couldn't find one.
Thanks a lot,
Miri
<esri:Legend.LegendItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Margin="0,-3"> <TextBlock Text="{Binding Label}" Margin="5,0" VerticalAlignment="Center" MinWidth="80" /> <Image Source="{Binding ImageSource}" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" MinWidth="20" Margin="0,-1" /> </StackPanel> </DataTemplate> </esri:Legend.LegendItemTemplate>
Issue #1: Look at the attached image. I need the groups : USAID-related, Political/Administrative, Infrastructure, Israel-related to behave like TreeView (i.e. collapse/visible). Only the root element: USAID_Layers is redundant.
<esri:Legend.Template> <ControlTemplate TargetType="esri:Legend" xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" xmlns:sdk="clr-namespace:System.Windows;assembly=System.Windows.Controls"> <toolkit:TreeView ItemsSource="{Binding LayerItemsSource[0].LayerItemsSource, RelativeSource={RelativeSource TemplatedParent}}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" > <toolkit:TreeView.ItemTemplate> <sdk:HierarchicalDataTemplate ItemsSource="{Binding LayerItemsSource}" > <ContentPresenter Content="{Binding}" ContentTemplate="{Binding Template}" /> </sdk:HierarchicalDataTemplate> </toolkit:TreeView.ItemTemplate> <toolkit:TreeView.ItemContainerStyle> <Style TargetType="toolkit:TreeViewItem"> <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/> <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/> </Style> </toolkit:TreeView.ItemContainerStyle> </toolkit:TreeView> </ControlTemplate></esri:Legend.Template>