Select to view content in your preferred language

Element Binding to Layer.Visible Property

1198
4
07-01-2010 04:48 AM
JingjingLi
Deactivated User
I have tried many times on Element Binding to Layer.Visible Property but had no success. My thinking is using a series of RadioButtons to control layer visibility in a Map instance. Just have no idea why it does not work. Anyone can help me will be appreciated.
:::XAML:::
<UserControl x:Class="RadioButtonDataBinding.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        
        
        <esri:Map x:Name="MyMap" Extent="-120,20,-90,60" Grid.Row="0">
            <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" 
                Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer"
                Visible="{Binding IsChecked, ElementName=rbtn01}"/>
            <esri:ArcGISDynamicMapServiceLayer ID="DynamicLayer" Opacity="0.6" 
                Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"
                Visible="{Binding IsChecked, ElementName=rbtn02}" />
        </esri:Map>

        <StackPanel Orientation="Horizontal" Grid.Row="1">
            <RadioButton x:Name="rbtn01" IsThreeState="False" IsChecked="True" 
                         Content="World 2D Map" Margin="5" GroupName="MapLayers" Checked="rbtn01_Checked" Unchecked="rbtn01_Unchecked"/>
            <RadioButton x:Name="rbtn02" IsThreeState="False" IsChecked="False" 
                         Content="USA Map" Margin="5" GroupName="MapLayers" Checked="rbtn02_Checked" Unchecked="rbtn02_Unchecked"/>
        </StackPanel>

        <StackPanel Orientation="Horizontal" Grid.Row="2">
            <Button Content="Button 01" Width="100" Height="25" IsEnabled="{Binding IsChecked, ElementName=rbtn01}" Margin="5"/>
            <Button Content="Button 02" Width="100" Height="25" IsEnabled="{Binding IsChecked, ElementName=rbtn02}" Margin="5"/>
        </StackPanel>
    </Grid>
</UserControl>
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
Reverse the orientation of the binding:

 
<esri:Map x:Name="MyMap" Extent="-120,20,-90,60" Grid.Row="0">
<esri:ArcGISTiledMapServiceLayerID="StreetMapLayer" 
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer"
Visible="True"/>
<esri:ArcGISDynamicMapServiceLayer ID="DynamicLayer" Opacity="0.6" 
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"
Visible="False" />
</esri:Map>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<RadioButton x:Name="rbtn01" IsThreeState="False" IsChecked="{Binding Layers[0].Visible, ElementName=MyMap, Mode=TwoWay}" 
Content="World 2D Map" Margin="5" GroupName="MapLayers" />
<RadioButton x:Name="rbtn02" IsThreeState="False" IsChecked="{Binding Layers[1].Visible, ElementName=MyMap, Mode=TwoWay}" 
Content="USA Map" Margin="5" GroupName="MapLayers"/>
</StackPanel>


That being said, I can't explain why it's not working other way....
0 Kudos
dotMorten_esri
Esri Notable Contributor
That being said, I can't explain why it's not working other way....


...because you are binding from a non-UIElement.
0 Kudos
DominiqueBroux
Esri Frequent Contributor

...because you are binding from a non-UIElement.


Looks like a good explanation, Thanks Morten

PS : I thought SL4 had extended some binding possibilities to non UI elements but obviously not until this case.
0 Kudos
JingjingLi
Deactivated User
...because you are binding from a non-UIElement.


Thanks Morten and Dominique. I didn't realize it's not a UI element.
I tried the reverse way and it worked. I just had no idea why the other way binding doesn't work.
0 Kudos