Question

I have an application that uses MEF and Caliburn.Micro. The main view has canvas and a button. The button when clicked, should create a new widget and display it in the canvas. The widget in this case is a UserControl that has a view and viewmodel. The user can add 0-N of these widgets to the canvas.

I have the widget in the MEF catalog but I can't seem to find an example of how to wire it up in Caliburn.Micro.

Any ideas what I'd write in the main view model when that button is pressed?

Était-ce utile?

La solution

You should have a collection of view models that your Canvas binds to. In fact, if you use a Conductor collection type in Caliburn.Micro (have a look at Conductor<T>.Collection.AllActive), then it already has an Items collection.

When the button is clicked, your main view model verb (method) can add a new view model to the Items collection. Your main view model will therefore need a view model factory injected in order to create these child view models.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top