Select to view content in your preferred language

Binding Slider to Opacity

2820
1
04-15-2010 04:58 PM
JimJackson
New Contributor
For some reason I can't get the standard element-to-element binding working with a simple map with 2 layers and a slider that should be operating on the opacity of the top layer. Here is my xaml, any ideas?

        <Slider x:Name="slider1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Maximum=".7" LargeChange="0.1" SmallChange="0.05" Minimum=".1" Value=".1" />
        <esri:Map Background="White" Grid.Row="1" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="map1" VerticalAlignment="Stretch" >
            <esri:Map.Layers>
                <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
                <esri:ArcGISTiledMapServiceLayer ID="TopoMap" Opacity="{Binding Value, ElementName=slider1}" Url="http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer" />
            </esri:Map.Layers>
        </esri:Map>
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
The problem is that ArcGISTiledMapServiceLayer is a DependencyObject and not a FrameworkElement.
With Silverlight 3, a property must be a FrameworkElement  dependency property in order to be a binding target.

Your code should work by reversing the binding:

<Slider x:Name="slider1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Maximum=".7" LargeChange="0.1" SmallChange="0.05" Minimum=".1" 
   Value="{Binding ElementName=map1, Path=Layers[1].Opacity, Mode=TwoWay}" />
<esri:Map Background="White" Grid.Row="1" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="map1" VerticalAlignment="Stretch" >
 <esri:Map.Layers>
  <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
  <esri:ArcGISTiledMapServiceLayer ID="TopoMap" Opacity="0.1" Url="http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer" />
 </esri:Map.Layers>
</esri:Map>


Dominique
0 Kudos