Solved! Go to Solution.
private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
{
if (e.LayerItem.LayerItems != null)
{
foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems)
{
if (layerItemVM.Label == "myLayer")
{
layerItemVM.Label = layerItemVM.Label + " additional text";
}
}
}
}
<TextBlock Text="{Binding Layer.CopyrightText} /><TextBlock Text="{Binding Tag} />
<userControls:DraggableWindow IsOpen="True"
x:Name="MapLegendWindow"
Margin="0,27,17,225" Padding="0"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Title="Map Legend" Background="{StaticResource BaseColor}"
HorizontalAlignment="Right" Width="205">
<i:Interaction.Triggers>
<i:EventTrigger>
<!--<actions:ToggleWindowVisibilityAction />-->
<!-- Hide at startup -->
</i:EventTrigger>
</i:Interaction.Triggers>
<esri:Legend x:Name="Legend" Map="{Binding ElementName=Map}"
LayerIDs="AllAvailableFeatureLayer, AMAvailableLayer, PMAvailableLayer, NoneAvailableLayer"
LayerItemsMode="Flat"
ShowOnlyVisibleLayers="False"
Refreshed="Legend_Refreshed"/>
</userControls:DraggableWindow> private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
{
LayerItemViewModel removeLayerItemVM = null;
if (e.LayerItem.LayerItems != null)
{
foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems)
{
if (layerItemVM.IsExpanded)
layerItemVM.IsExpanded = true;
}
if (removeLayerItemVM != null)
e.LayerItem.LayerItems.Remove(removeLayerItemVM);
}
else
{
e.LayerItem.IsExpanded = true;
}
{
if (e.LayerItem.Label == "AllAvailableFeatureLayer")
e.LayerItem.Label = "AM and PM Available";
if (e.LayerItem.Label == "AMAvailableLayer")
e.LayerItem.Label = "Only AM Available";
if (e.LayerItem.Label == "PMAvailableLayer")
e.LayerItem.Label = "Only PM Available";
if (e.LayerItem.Label == "NoneAvailableLayer")
e.LayerItem.Label = "No Times Available";
}
}
<Style TargetType="esri:Legend">
<Setter Property="LayerItemsMode" Value="Flat" />
<Setter Property="LayerTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}" >
</CheckBox>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="MapLayerTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}" >
</CheckBox>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Alternatively to the modification of the label by code, you can also change the MapLayerTemplate and add UIElement binded to any LayerItemViewModel property.
One of the most useful property is the Layer property that allows accessing all layer properties. Example to display layer CopyrightText:<TextBlock Text="{Binding Layer.CopyrightText} />
For more complex scenario, we can also populate the Tag property by code and include it in the template:<TextBlock Text="{Binding Tag} />
When I add textboxes to my current code (see my post # 4 for more info) it doesn't show up.
But I you add textboxes in the datatemplate of the LayerTemplate and/or of the MapLayerTemplate, you should for sure see them in the legend next to the checkbox.
<userControls:DraggableWindow IsOpen="True"
x:Name="MapLegendWindow"
Margin="0,27,17,225" Padding="0"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Title="Map Legend" Background="{StaticResource BaseColor}"
HorizontalAlignment="Right" Width="305">
<i:Interaction.Triggers>
<i:EventTrigger>
<!--<actions:ToggleWindowVisibilityAction />-->
<!-- Hide at startup -->
</i:EventTrigger>
</i:Interaction.Triggers>
<esri:Legend x:Name="Legend" Map="{Binding ElementName=Map}"
LayerIDs="Labels, AllAvailableFeatureLayer, AMAvailableLayer, PMAvailableLayer, WkEndAvailableLayer, CurrentlyUnAvailableLayer, NoneAvailableLayer"
LayerItemsMode="Flat"
ShowOnlyVisibleLayers="False"
Refreshed="Legend_Refreshed"/>
</userControls:DraggableWindow>
<StackPanel Background="LightGray">
<TextBlock TextWrapping="Wrap" Text="Select the timeslots you would like to review."/>
<esri:Legend x:Name="Legend" Map="{Binding ElementName=Map}"
LayerIDs="Labels, AllAvailableFeatureLayer, AMAvailableLayer, PMAvailableLayer, WkEndAvailableLayer, CurrentlyUnAvailableLayer, NoneAvailableLayer"
LayerItemsMode="Flat"
ShowOnlyVisibleLayers="False"
Refreshed="Legend_Refreshed"/>
</StackPanel>