MVVM for Graphics Overlays

725
2
12-08-2018 11:57 AM
CharlesRoberts1
New Contributor III

Most WPF .Net 100.X samples use a Static Resource of the Map object declared in the xaml file. Then the Map property of the MapView control is set to Static Resource instance. I would like to do the same for Graphics overlays but this does not seem to be possible. The exposed Overlays property is for an unrelated Items control. Sure, I can use the somewhat confusing approach as is demonstrated in the "Controller" samples (demonstrates injecting a "weak" reference to the MapView into the view model to control, for example, the map viewpoint from the ViewModel), but is there no more straight forward  way?

0 Kudos
2 Replies
dotMorten_esri
Esri Frequent Contributor

The approach I'd suggest is you create a view model that contains both a Map and a GraphicsOverlayCollection, then set the datacontext to that viewmodel. Then you'll merely bind the two to the mapview:

<esri:MapView Map="{Binding Map}" GraphicsOverlays="{Binding Overlays}" />

0 Kudos
CharlesRoberts1
New Contributor III

Ah, of course. I was thrown off by the Overlays property and did not notice GraphicsOverlays.

Thank you for steering me in the right direction.

0 Kudos