by Jon Sigfusson
17. March 2011 07:34
Last night I was working on my favorite hobby project Campaign Planner when I came across a situation where I wanted to handle some user interaction in a user control. When editing a path the user needs to be able to set the precise time of a path point. Now the question I posed myself was: How does the control (or the view model class) initiate a dialog with the user?
I did come up with a solution the next day. Say you wanted the dialog with the user to occur in a modal window then the solution must be: The view model (MVVM) must be the initiator. The user control must handle the creation of the dialog window. You can make this happen with a public event on the view model class and having the user control handle the event by creating a modal dialog window.
Another solution would be to expose a property on the view model class that the user control is bound to and can change visual appearance to support a dialog with the user.
In the case of the modal dialog window I did ponder other options, such as letting the view model class event bubble up the view model hierarchy to the main window view model class where I already handle several other user interaction events. But I must admit that while a little code is required in the view (user control) the simplicity of the solution outweighs the cost.
More to come…
761349ae-7964-4388-9680-622d186dc4da|0|.0
Tags:
Programming