0
votes

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

1
Please include the code and the error message you get in the post. And provide a minimum reproducible example that highlights the problem. - sanastasiadis
Hello @sanastasiadis thanks for your reply. The project is attached (Dropbox link). I don't get any error. My viewmodels just don't show up in my test TabControl. In the Wpf application everything is fine. - Maximilian Wallinger
Your question will probably attract more answers if it has copy-pasted critical parts of your code. Keep the download link as a supplementary reference. - sanastasiadis

1 Answers

1
votes

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.