Monday, May 19, 2014

ESRI Legend Control - Show and Hide Sliders

In the ESRI Legend Control, "DataTemplate" can be used to display slider "usercontrol" to control the opacity of the Layer.
 
Here is the XAML content where the slider "usercontrol" is used.
 
      
<esri:Legend Grid.Row="1" x:Name="legendControl" VerticalAlignment="Top" LayerItemsMode="Tree"
ShowOnlyVisibleLayers="False" Margin="5,5,5,5" ><esri:Legend.MapLayerTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}" >
</CheckBox>
<Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" Loaded="Slider_Loaded" Tag="{Binding Layer}" />
</StackPanel>
</DataTemplate>
</esri:Legend.MapLayerTemplate>
<esri:Legend.LayerTemplate>
<DataTemplate>
<CheckBox Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}" >
</CheckBox>
</DataTemplate>
</esri:Legend.LayerTemplate>
</esri:Legend>


But what happens, if the user should see Slider usercontrol only for certain Layers and for certain Layers it should NOT be shown ?

There are many ways to do this. But here is one simple method.

In the Slider "usercontrol" add the following event and tag in the XAML content.

Loaded="Slider_Loaded" Tag="{Binding Layer}"

In the code behind simply use some logic like this.

private void Slider_Loaded(object sender, RoutedEventArgs e)
{Slider slider = sender as Slider;
Layer layer = slider.Tag as Layer;
if (layer.ID == "SampleData") slider.Visibility = System.Windows.Visibility.Collapsed;
}

If the "Layer.ID" matches with that "specific layer name", then the slider will not be displayed.

Hope this helps !

Have fun coding :)

Cheers
Adam





 

No comments:

Post a Comment

All Blogs so far ...