Caliburn.Micro: Creating and Binding to Software

I am currently experimenting with the composition of the species in Caliburn.Micro. I have a working example where I have several user-control-based views introduced into my main shell using the route of the attached property "View.Model". So far so good.

In my application, I work with a mixed environment, mainly WinForms, with some WPFs, so there is no WPF wrapper for Caliber for WPL. I would like to be able to create my opinions on demand and add them to the placeholders in my WinForms application.

I would like to know how I am going to create a view (which will be a user control containing sub-user controls) programmatically using Caliburn so that all conventions, model bindings, and subtask nesting are executed.

+5
source share
2 answers

Caliburn ViewModelBindercan be used for a crank descriptor when you have a view instance and an appropriate view model. The call Bindresolves the entered views and applies binding based on the agreement, etc.:

    SomeCompositionView view = new SomeCompositionView();

    ISomeCompositionViewModel viewModel = IoC.Get<ISomeCompositionViewModel>();

    ViewModelBinder.Bind(viewModel, view, null);

    ElementHost.Child = view;  
+13
source

Code snippet from BootstrapperBase.DisplayRootViewFor:

var viewModel = IoC.GetInstance(viewModelType, null);
var view = ViewLocator.LocateForModel(viewModel, null, null);

ViewModelBinder.Bind(viewModel, view, null);

var activator = viewModel as IActivate;
if(activator != null)
    activator.Activate();
+10
source

All Articles