Select to view content in your preferred language

FeatureLayer visibility binding to checkbox

2767
1
Jump to solution
06-06-2012 03:25 AM
bayramüçüncü
Deactivated User
I have used the sample here.
But I added a checkbox and bind it to feature layers visibility. But not worked.

<esri:Map x:Name="MyMap" WrapAround="True" Extent="-15000000,2000000,-7000000,8000000">
            <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                    Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>

            <esri:FeatureLayer ID="MyFeatureLayer"
                    Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/Map..."
                    Where="POP1990 > 100000" Renderer="{StaticResource MySimplePointRenderer}"
                    Visible="{Binding ElementName=checkBox1,Path=IsChecked,Mode=TwoWay}"/>
        </esri:Map>
       <CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="25,12,0,0" Name="checkBox1" VerticalAlignment="Top" />
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
Hi Bayram,

The layers are not FrameworkElements and thus have no DataContext. So binding to an element name that is supposed to be in the Visual Tree doesn't work.

You can get it working by initiating the binding from the checkbox. Something like:

<esri:Map x:Name="MyMap" WrapAround="True" Extent="-15000000,2000000,-7000000,8000000"> <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>  <esri:FeatureLayer ID="MyFeatureLayer" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0"  Where="POP1990 > 100000" Renderer="{StaticResource MySimplePointRenderer}"/> </esri:Map> <CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="25,12,0,0" VerticalAlignment="Top"        DataContext="{Binding Layers, ElementName=MyMap}"       IsChecked="{Binding [MyFeatureLayer].Visible, Mode=TwoWay}" /> 

View solution in original post

0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
Hi Bayram,

The layers are not FrameworkElements and thus have no DataContext. So binding to an element name that is supposed to be in the Visual Tree doesn't work.

You can get it working by initiating the binding from the checkbox. Something like:

<esri:Map x:Name="MyMap" WrapAround="True" Extent="-15000000,2000000,-7000000,8000000"> <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>  <esri:FeatureLayer ID="MyFeatureLayer" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0"  Where="POP1990 > 100000" Renderer="{StaticResource MySimplePointRenderer}"/> </esri:Map> <CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="25,12,0,0" VerticalAlignment="Top"        DataContext="{Binding Layers, ElementName=MyMap}"       IsChecked="{Binding [MyFeatureLayer].Visible, Mode=TwoWay}" /> 
0 Kudos