Select to view content in your preferred language

Changing font color in Legend?

821
2
03-18-2011 07:28 AM
MatthewCarey
Regular Contributor
Hopefully a simple one -

I've used the 'Legend with Templates' sample code to add a legend, and it's working well.

The default text in the legend was black but I've managed to change the font to white for both the name of each map service and for each individual layer within those, using 'Foreground="White"' in the XAML code below:
<esri:Legend Map="{Binding ElementName=MyMap}"  
                         LayerItemsMode="Tree" 
                         ShowOnlyVisibleLayers="False"
                         Refreshed="Legend_Refreshed"
                         Name="MyLegend"
                         Background="Transparent"
                         BorderThickness="0"
                         Foreground="White" >
                            
                            <esri:Legend.MapLayerTemplate>
                                
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <CheckBox Content="{Binding Label}"
                        IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                        IsEnabled="{Binding IsInScaleRange}"
                                          Foreground="White">
                                        </CheckBox>
                                        <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" />
                                   </StackPanel>
                                </DataTemplate>
                                
                                
                            </esri:Legend.MapLayerTemplate>
                            
                            
                            <esri:Legend.LayerTemplate>
                                <DataTemplate>                     
                                    <CheckBox Content="{Binding Label}"
                       IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                IsEnabled="{Binding IsInScaleRange}" 
                                        Foreground="White" >
                                    </CheckBox>
                                </DataTemplate>
                            </esri:Legend.LayerTemplate>
                        

                        </esri:Legend>


What I can't seem to manage is to make the font white when you expand a layer and view the symbology for that layer (please see attached image).

Does anyone know how I would achieve this, assuming it's possible? Thanks a lot.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
You can either change the LegendItemTemplate
<esri:Legend.LegendItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,-1">
<Image Source="{Binding ImageSource}" HorizontalAlignment="Center" VerticalAlignment="Center"
               Stretch="None" MaxHeight="55" MaxWidth="55" MinWidth="20" Margin="0,-1" />
<TextBlock Text="{Binding Label}" Margin="5,0,0,0" VerticalAlignment="Center" Foreground="White"/>
</StackPanel>
</DataTemplate>
</esri:Legend.LegendItemTemplate>


or change the template by setting the foreground of the treeview. This changes will apply to all treeview items having no foreground specified.

Note that setting the foreground of the control itself (<esri:Legend Foreground=.....) should work as well but is not due a bug. This bug will be fixed in a future version.
0 Kudos
MatthewCarey
Regular Contributor
Your first suggestion worked for me, thanks!
0 Kudos