Layer.IsVisible binding not working

08-22-2017 04:49 AM
New Contributor

Is it possible to set (working) binding on Layer.IsVisible property? As far as I tried, I could not manage to make it work. 

         <esri:WmtsLayer ServiceUri=""
                IsVisible="{Binding ShowBaseLayer}"/>

On my view model, PropertyChanged event is raised properly whenever the ShowBaseLayer property changes. However, the layer is always visible, no matter what the value of ShowBaseLayer property is.

Am I missing something here? Is my approach correct? (Binding works properly on the rest of my page, thus there is no problem with setting DataContext/wrong DataContext/etc. here)

I am using ArcGIS Runtime 10.2.7 for Desktop.

Thanks for any tips,


0 Kudos
1 Reply
Esri Frequent Contributor

Binding expressions are only valid on objects that inherit from FrameworkElement controls (ie the MapView), since only these have a DataContext. A Map isn't a FrameworkElement, and thus doesn't inherit a DataContext.

The way we suggest you build your app is to put your Map (with all its layers in your ViewModel), you then bind this to the MapView. 

Similarly you could bind List Control to the Map's Layers collection, and inside the list place CheckBoxes that binds to the Layer's IsVisible property.

So think of it this way: "Your Map is the model, the MapView is the view."

<esri:MapView Map="{Binding Map, Mode=OneWay}" />

<CheckBox IsChecked="{Binding Map.Layers[0].IsVisible, Mode=TwoWay}" />

0 Kudos