Maximilian Wallinger
Maximilian Wallinger

Reputation: 11

Caliburn Micro Winforms MEF Implementation

My name is Max. I'm currently working on a projekt with caliburn micro. I'm trying to create a plugin based application in C# with the help of MEF.

I'm using WPF. So I stripped my application to the bare minimum. The bindings with caliburn works fine in the test WPF application. The problem what I have now is that the ShellView (WPF UserControl) needs to live in an ElementHost of a WinForm 3rd party application.

I can't figure it out how to create the correct binding. So that the "magic" of caliburn also works in the winform application. Maybe one of you cracks can help me. I googled and tried this an entire day.

Your help would be very much appreciated. Greets Max

Link to project: https://www.dropbox.com/s/y88kgnh0wscy2jr/CaliburnMEF_Example.zip?dl=0

Upvotes: 0

Views: 308

Answers (1)

mvermef
mvermef

Reputation: 3914

Sample that was provided on the CM GitHub its been there a while..., https://github.com/Caliburn-Micro/Caliburn.Micro/tree/master/samples/Caliburn.Micro.WinFormsInterop/Caliburn.Micro.WinFormsInterop

--edit-- You were close compare this code snippet to your current test project. You were missing a few key items... reference comments

 protected override void StartRuntime()
 {
        base.StartRuntime();

        var vm = IoC.Get<ShellViewModel>(); // ok
        var view = ViewLocator.LocateForModel(vm, null, null); // needed

        //binds the viewmodel to the view & wire up controls...
        ViewModelBinder.Bind(vm, view, null); // required!

        var activator = vm as IActivate; // required

        if (activator != null)
            activator.Activate();  // required

        _host.Child = view;   // since Forms is ViewFirst, by default.

 }

Just a few extra steps to get it work with the ElementHost control. As for binding it should work as expected. If you are having issues with binding other controls (3rd party), you might have to create Conventions to support them. That is a very dependent on the controls themselves.

Upvotes: 1

Related Questions