0

I need to bind an ArcGIS Map from the ArcGIS Runtime SDK for .NET to a view model which provides a collection of custom models which represent the data of the individual ArcGIS Layers (used for serialization purposes). Now since ArcGIS is not really MVVM friendly (most 'Controls' are just DependencyObjects, have no data context or don't support templating), my initial idea is to wrap the MapView in a custom control which derives from ItemsControl which I bind to my custom types and then select the appropriate DataTemplate for the type which contains an ArcGIS Layer that is being rendered into the map. Something like this:

<local:MapViewAdapter ItemsSource="{Binding MyCustomTypes}">
    <local:MapViewAdapter.Resources>
        <DataTemplate DataType="{x:Type ArcGISDrawLayer}">
            <GraphicsLayer GraphicsSource="{Binding LayerGraphics}" />
        </DataTemplate>
        ...
    </local:MapViewAdapter.Resources> 
</local:MapViewAdapter>

The MapViewAdapter should internally create a new MapView along with it's Map and then render the specified DataTemplates into the LayerCollection of the Map.

However I have no idea how to accomplish this without re-implementing most of the ArcGIS controls. Any ideas?

artganify
  • 683
  • 1
  • 8
  • 23

1 Answers1

0

Now since ArcGIS is not really MVVM friendly (most 'Controls' are just DependencyObjects, have no data context or don't support templating)

Only UI controls have datacontext, and naturally non-UI objects like layers doesn't have templates, since that only applies to UI objects. That's just how XAML works. Instead you should think of your Map as you model data that you bind to your MapView, and not the individual layers inside the map.

You can create a IValueConverter that converts your graphics layer into a map which you then bind to you map, or even better, simple have Maps in you models.

<esri:MapView Map="{Binding Map}" />
dotMorten
  • 1,953
  • 1
  • 14
  • 10