artganify artganify -4 years ago 101
C# Question

Calling method on control in MVVM

I'm currently working with the ArcGIS Runtime SDK .NET where I'd like to have the current viewport of the map bound to a property on my view model. However, the view port (expressed as

) does not have a setter, despite being a dependency property.

In order to set the viewport, I need to call a method on the control. But how do I do that from the view model? I already found similiar questions here on SO, but most of them were answered with The view model shouldn't be aware of the view. I agree with that, but unfortunately I can't change the fact that the setter of a property on a proprietary control is a different method than the actual property I can bind to and read values from.

Answer Source

There are many ways to do the job that might be considered MVVM friendly. The one that I suggest is that you wrap your ArcGIS view in a custom control that you have full control over. This way you can expose your required dependency properties and handle their setters in your custom control.

I use this method almost every time I'm using a third-party component this way I make the component loosely coupled with my other code and I can replace them easily.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download