Allan Jiang
Allan Jiang

Reputation: 11331

MVVM Design Pattern for Windows Phone

I am writing a Windows Phone application and planned to use some MVVM idea in it.
I know that with command binding I can easily separate UI and logic, but the problem is I don't know how I can get access to the controls properties, for example:
I have a map control on the main page, for which I want to show a push pin at the place user taps at. But with MVVM I don't think there is anyway I can do that. Means I can not access to the maps properties and methods to do things like that, is it right?

If anyone has experience with MVVM please share your idea about how to use control's properties and methods to perform tasks.

(P.S. I dont want to use MVVM Light or any toolkit for this application)

Thank you

Upvotes: 2

Views: 598

Answers (1)

Gergely Orosz
Gergely Orosz

Reputation: 6485

What you're trying to do - binding a to a property which determines where to show a pin on the map - is a pretty specific use case, which is why the map control does not expose a property for this.

If you want to follow the MVVM pattern I would recommend creating a user control / custom control that wraps the map control and exposes a dependency property to which you can bind to. When this property is changed you check if there's a pin added to the map and if not, add one; otherwise move it to the correct position.

Bottom line is you'll need to create some custom control and expose the property/properties to bind to if you want to implement the solution following the MVVM pattern.

Upvotes: 5

Related Questions