Select to view content in your preferred language

How to Control Visibilty and Opacity from XAML

1125
2
10-26-2011 02:02 PM
RobertPincus
Regular Contributor
How can I toggle the visibility and opacity of certain layers from XAML? I do not want to bind the controls to all the layers in the map, only some of them.
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
You can use this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LayerList and use a different LayerCollection for ItemsSource.

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <esri:LayerCollection x:Key="MyLayers"/>
        </Grid.Resources>


<ListBox x:Name="MyList" ItemsSource="{StaticResource MyLayers}">


         public MainPage()
        {
            InitializeComponent();

            var layers = LayoutRoot.Resources["MyLayers"] as LayerCollection;
            foreach (var l in MyMap.Layers)
            {
                //only add layers you want to control visibility/opacity 
                layers.Add(l);
            }
        }



0 Kudos
dotMorten_esri
Esri Notable Contributor
If you just want to bind to a specific layer, use elementbinding and path (in the sample below the layer ID this is binding to is 'layerID'):
<Slider Value="{Binding ElementName=MyMap, Path=Layers[layerID].Opacity, Mode=TwoWay}" Minimum="0" Maximum="100" />
<CheckBox IsChecked="{Binding ElementName=MyMap, Path=Layers[layerID].Visible, Mode=TwoWay}" />
0 Kudos