ArcGISTiledMapServiceLayer's ServiceUri not binding to View Model's String Property

2617
3
Jump to solution
10-02-2015 11:35 AM
RonVincent
Occasional Contributor

This is in regards to ArcGIS Runtime SDK for .NET (WPF) 10.2.6.. I have a ArcGISTiledMapServiceLayer and ArcGISDynamicMapServiceLayer that are attempting to get their ServiceUri from a string property on the View Model but it doesn't work. Other bindings work, even ones that are also string properties. ServiceUri is a string.

<esri:ArcGISTiledMapServiceLayer ID="Basemap"
          ServiceUri="{Binding Path=BasemapUri}"/>

<esri:ArcGISDynamicMapServiceLayer ID="USA" 
                         ServiceUri="{Binding USAUri}"/>

Any ideas as to why this would happen? I'm using MVVM Light. It's a string according to this:

ArcGISTiledMapServiceLayer.ServiceUri Property

Thanks,

Ron

0 Kudos
1 Solution

Accepted Solutions
ThadTilton
Esri Contributor

Hi Ron -

The problem is that elements inside the MapView are not contained in the Page's control hierarchy. If you set a data context for the Page (or Window) it won't be available on things like Map and Layer. Since those things don't inherit from FrameworkElement, they won't be able to use the data context of elements that "contain" them.

If you define the data source explicitly with the binding, it should work as expected.

Here's an example of binding a layer's ServiceUri to a property in a ViewModel. The ViewModel has been defined as a static resource in App.xaml.

<esri:ArcGISTiledMapServiceLayer ID="Basemap"

ServiceUri="{Binding Source={StaticResource myVM}, Path=BaseMapUri}"/>

View solution in original post

0 Kudos
3 Replies
ThadTilton
Esri Contributor

Hi Ron -

The problem is that elements inside the MapView are not contained in the Page's control hierarchy. If you set a data context for the Page (or Window) it won't be available on things like Map and Layer. Since those things don't inherit from FrameworkElement, they won't be able to use the data context of elements that "contain" them.

If you define the data source explicitly with the binding, it should work as expected.

Here's an example of binding a layer's ServiceUri to a property in a ViewModel. The ViewModel has been defined as a static resource in App.xaml.

<esri:ArcGISTiledMapServiceLayer ID="Basemap"

ServiceUri="{Binding Source={StaticResource myVM}, Path=BaseMapUri}"/>

0 Kudos
RonVincent
Occasional Contributor

Thad,

Thanks for your reply. Once again you've helped me head down the right path with this. I had to do the following because of the Locator in MVVM Light:

<esri:ArcGISTiledMapServiceLayer ID="Basemap"

  ServiceUri="{Binding MainViewModel.BasemapUri, Source={StaticResource Locator}}"/>

Ron

0 Kudos
ThadTilton
Esri Contributor

Awesome, glad you were able to crack it! Looks like MVVM Light adds an extra layer of complexity to the binding.

Thanks for posting your solution for others who will (inevitably) run into this problem.

Thad

0 Kudos