Control Naming in 2.1 API Legend Control

675
3
01-06-2011 08:49 AM
PaulHuppé
Occasional Contributor
In the 2.1 API Legend Control used in the online samples, the layers are displayed in the legend using the template:

                <esri:Legend.LayerTemplate>
                    <DataTemplate>
                        <CheckBox Content="{Binding Label}"
                   IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                IsEnabled="{Binding IsInScaleRange}" >
                        </CheckBox>
                    </DataTemplate>
                </esri:Legend.LayerTemplate>


In the CheckBox control, is it possible to name the control using map layer name and its parent service?  I.E.:  something like x:Name="cbx + {Binding ParentServiceName} + {Binding Label}" and also remove any blanks in those name.

For example, if I have a service called "Bedrock Index Map" and a layer in it called "Bedrock Geology", then my CheckBox name would become "cbxBedrockIndexMapBedrockGeology".

Can this be done?

P.S.: Where do we get the list of things we can use for Binding?  Is Label a property of a layer in a map service?
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor

P.S.: Where do we get the list of things we can use for Binding? Is Label a property of a layer in a map service?


The data context of one item is set to a LayerItemViewModel object (see documentation).

You can notice that this object has a 'Layer' property which is the map layer where the legend item is coming from.

By using this layer property you can access to any property of the layer.
As an example, you can use Layer.ID to get what you want:
<esri:Legend.LayerTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay}" 
                             IsEnabled="{Binding IsInScaleRange}" VerticalAlignment="Center">
<CheckBox.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Layer.ID, StringFormat='\{0\} / '}" />
<TextBlock Text="{Binding Label}" />
</StackPanel>
</CheckBox.Content>
</CheckBox>
</StackPanel>
</DataTemplate>
</esri:Legend.LayerTemplate>
0 Kudos
dotMorten_esri
Esri Notable Contributor
You cannot do dynamic naming on items in an ItemsControl. I'm not sure this even makes any sense to do. Remember these are templates and not actual UIElement instances, so the naming on them usually don't mean anything to your app.
0 Kudos
PaulHuppé
Occasional Contributor
Morten:
Ok, I will have to find another way to do what I want.

Dominique:
Thanks for the information.
0 Kudos