How to use Caliburn Micro in a WinForms app with one WPF formHow do I use WPF bindings with RelativeSource?How to speed up WPF developmentWinForms to WPF - How do we get there from here?Caliburn Micro with WPF MouseBindingWPF Context Menus in Caliburn MicroHow to dispose of Autofac container used with Caliburn MicroCaliburn micro in no Application object mode, like in AutoCAD dll pluginCreating a form from a WinForms Control hosted within WPF — Owner is not setWinform desktop app and touchWinForms app changes its scaling after opening WPF window from form

How can a single Member of the House block a Congressional bill?

Racetrack designers, assemble!

Why would Lupin kill Pettigrew?

Asking for something with different prices

What is the most important characteristic of New Weird as a genre?

Parsing CSV with AWK to Produce HTML Output

Can you use a concentration spell while using Mantle of Majesty?

Is the capacitor drawn or wired wrongly?

Why use water tanks from a retired Space Shuttle?

Self-Preservation: How to DM NPCs that Love Living?

What's the most polite way to tell a manager "shut up and let me work"?

Is American Express widely accepted in France?

How did the Zip Chip and RocketChip accelerators work for the Apple II?

Asking bank to reduce APR instead of increasing credit limit

How to detach yourself from a character you're going to kill?

Why don't I have ground wiring on any of my outlets?

How much current can Baofeng UV-5R provide on +V pin?

Explain Ant-Man's "not it" scene from Avengers: Endgame

Future enhancements for the finite element method

Can I ask a publisher for a paper that I need for reviewing

What is a simple, physical situation where complex numbers emerge naturally?

How can I offer a test ride while selling a bike?

Joist hangers to use for rough cut 2x8 (2 3/4" x 8 3/4")?

How to properly maintain eye contact with people that have distinctive facial features?



How to use Caliburn Micro in a WinForms app with one WPF form


How do I use WPF bindings with RelativeSource?How to speed up WPF developmentWinForms to WPF - How do we get there from here?Caliburn Micro with WPF MouseBindingWPF Context Menus in Caliburn MicroHow to dispose of Autofac container used with Caliburn MicroCaliburn micro in no Application object mode, like in AutoCAD dll pluginCreating a form from a WinForms Control hosted within WPF — Owner is not setWinform desktop app and touchWinForms app changes its scaling after opening WPF window from form






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








5















We have a (massive) legacy WinForms app which, through a menu item, opens up a WPF form. This WPF form will host an Infragistics grid, and some buttons/drop-downs.



This lone WPF form represents the nascent stage of a migration to WPF. Later on, more components of the app will move to WPF, and ultimately the entire app itself.



As part of the migration, we would like to use Caliburn Micro. Hence, it would be nice if we could start by using it with this lone WPF form.



  • Can someone please provide some pointers on how to use Caliburn Micro with the WPF form?

  • Or perhaps tell me why it may not make sense to use Caliburn Micro just yet?

The documentation I've read so far involves boot strappers that ensure the application starts with the desired root view model, rather than the scenario above.



Many thanks!










share|improve this question






















  • I think, in this case, C.M. will cause you more trouble than solve. C.M. is meant to help pure WPF apps get "up and running" faster with it's broad / automated MVVM framework. Your application is past the stage of building from a framework, and introducing a new one at this stage will be very challenging. What will probably help you the most is applying solid MVVM (the hard way), to transition to WPF. Since the project is in WinForms, there is a non-zero chance that it was built with a decent MVC implimentation, so this transition to MVVM might be less painful. Good luck!

    – EtherDragon
    Feb 1 '12 at 0:23


















5















We have a (massive) legacy WinForms app which, through a menu item, opens up a WPF form. This WPF form will host an Infragistics grid, and some buttons/drop-downs.



This lone WPF form represents the nascent stage of a migration to WPF. Later on, more components of the app will move to WPF, and ultimately the entire app itself.



As part of the migration, we would like to use Caliburn Micro. Hence, it would be nice if we could start by using it with this lone WPF form.



  • Can someone please provide some pointers on how to use Caliburn Micro with the WPF form?

  • Or perhaps tell me why it may not make sense to use Caliburn Micro just yet?

The documentation I've read so far involves boot strappers that ensure the application starts with the desired root view model, rather than the scenario above.



Many thanks!










share|improve this question






















  • I think, in this case, C.M. will cause you more trouble than solve. C.M. is meant to help pure WPF apps get "up and running" faster with it's broad / automated MVVM framework. Your application is past the stage of building from a framework, and introducing a new one at this stage will be very challenging. What will probably help you the most is applying solid MVVM (the hard way), to transition to WPF. Since the project is in WinForms, there is a non-zero chance that it was built with a decent MVC implimentation, so this transition to MVVM might be less painful. Good luck!

    – EtherDragon
    Feb 1 '12 at 0:23














5












5








5


1






We have a (massive) legacy WinForms app which, through a menu item, opens up a WPF form. This WPF form will host an Infragistics grid, and some buttons/drop-downs.



This lone WPF form represents the nascent stage of a migration to WPF. Later on, more components of the app will move to WPF, and ultimately the entire app itself.



As part of the migration, we would like to use Caliburn Micro. Hence, it would be nice if we could start by using it with this lone WPF form.



  • Can someone please provide some pointers on how to use Caliburn Micro with the WPF form?

  • Or perhaps tell me why it may not make sense to use Caliburn Micro just yet?

The documentation I've read so far involves boot strappers that ensure the application starts with the desired root view model, rather than the scenario above.



Many thanks!










share|improve this question














We have a (massive) legacy WinForms app which, through a menu item, opens up a WPF form. This WPF form will host an Infragistics grid, and some buttons/drop-downs.



This lone WPF form represents the nascent stage of a migration to WPF. Later on, more components of the app will move to WPF, and ultimately the entire app itself.



As part of the migration, we would like to use Caliburn Micro. Hence, it would be nice if we could start by using it with this lone WPF form.



  • Can someone please provide some pointers on how to use Caliburn Micro with the WPF form?

  • Or perhaps tell me why it may not make sense to use Caliburn Micro just yet?

The documentation I've read so far involves boot strappers that ensure the application starts with the desired root view model, rather than the scenario above.



Many thanks!







wpf caliburn.micro






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 31 '12 at 23:14









ck.ck.

6211023




6211023












  • I think, in this case, C.M. will cause you more trouble than solve. C.M. is meant to help pure WPF apps get "up and running" faster with it's broad / automated MVVM framework. Your application is past the stage of building from a framework, and introducing a new one at this stage will be very challenging. What will probably help you the most is applying solid MVVM (the hard way), to transition to WPF. Since the project is in WinForms, there is a non-zero chance that it was built with a decent MVC implimentation, so this transition to MVVM might be less painful. Good luck!

    – EtherDragon
    Feb 1 '12 at 0:23


















  • I think, in this case, C.M. will cause you more trouble than solve. C.M. is meant to help pure WPF apps get "up and running" faster with it's broad / automated MVVM framework. Your application is past the stage of building from a framework, and introducing a new one at this stage will be very challenging. What will probably help you the most is applying solid MVVM (the hard way), to transition to WPF. Since the project is in WinForms, there is a non-zero chance that it was built with a decent MVC implimentation, so this transition to MVVM might be less painful. Good luck!

    – EtherDragon
    Feb 1 '12 at 0:23

















I think, in this case, C.M. will cause you more trouble than solve. C.M. is meant to help pure WPF apps get "up and running" faster with it's broad / automated MVVM framework. Your application is past the stage of building from a framework, and introducing a new one at this stage will be very challenging. What will probably help you the most is applying solid MVVM (the hard way), to transition to WPF. Since the project is in WinForms, there is a non-zero chance that it was built with a decent MVC implimentation, so this transition to MVVM might be less painful. Good luck!

– EtherDragon
Feb 1 '12 at 0:23






I think, in this case, C.M. will cause you more trouble than solve. C.M. is meant to help pure WPF apps get "up and running" faster with it's broad / automated MVVM framework. Your application is past the stage of building from a framework, and introducing a new one at this stage will be very challenging. What will probably help you the most is applying solid MVVM (the hard way), to transition to WPF. Since the project is in WinForms, there is a non-zero chance that it was built with a decent MVC implimentation, so this transition to MVVM might be less painful. Good luck!

– EtherDragon
Feb 1 '12 at 0:23













3 Answers
3






active

oldest

votes


















6














After much Googling and going through the Caliburn Micro source code, I've come up with an approach that works in a sample test application. I can't post the test application here for certain reasons, but here's the approach in a nutshell.



  • Create a WinForm with a button.

  • On button click, show a ChildWinForm


  • In the load handler of the ChildWinForm:




    // You'll need to reference WindowsFormsIntegration for the ElementHost class
    // ElementHost acts as the "intermediary" between WinForms and WPF once its Child
    // property is set to the WPF control. This is done in the Bootstrapper below.
    var elementHost = new ElementHostDock = DockStyle.Fill;
    Controls.Add(elementHost);
    new WpfControlViewBootstrapper(elementHost);


  • The bootstrapper above is something you'll have to write.


  • For more information about all it needs to do, see Customizing the Bootstrapper from the Caliburn Micro documentation.

  • For the purposes of this post, make it derive from the Caliburn Bootstrapper class.


  • It should do the following in its constructor:




    // Since this is a WinForms app with some WPF controls, there is no Application.
    // Supplying false in the base prevents Caliburn Micro from looking
    // for the Application and hooking up to Application.Startup
    protected WinFormsBootstrapper(ElementHost elementHost) : base(false)

    // container is your preferred DI container
    var rootViewModel = container.Resolve();
    // ViewLocator is a Caliburn class for mapping views to view models
    var rootView = ViewLocator.LocateForModel(rootViewModel, null, null);
    // Set elementHost child as mentioned earlier
    elementHost.Child = rootView;




  • Last thing to note is that you'll have to set the cal:Bind.Model dependency property in the XAML of WpfControlView.




    cal:Bind.Model="WpfControls.ViewModels.WpfControl1ViewModel"


  • The value of the dependency property is used passed as a string to Bootstrapper.GetInstance(Type serviceType, string key), which must then use it to resolve the WpfControlViewModel.


  • Since the container I use (Autofac), doesn't support string-only resolution, I chose to set the property to the fully qualified name of the view model. This name can then be converted to the type, and used to resolve from the container.





share|improve this answer























  • You can use ViewModelBinder.Bind(rootViewModel, rootView, null); after ViewLocator.LocateForModel instead of cal:Bind.Model

    – Anders
    Jan 28 '14 at 14:40


















2














Following up on the accepted answer (good one!), I'd like to show you how to implement the WinForms Bootstrapper in a ViewModel First approach, in a way that:



  1. You won't have to create a WPF Window and,

  2. You won't have to bind directly to a ViewModel from within a View.

For this we need to create our own version of WindowManager, make sure we do not call the Show method on the Window (if applicable to your case), and allow for the binding to occur.



Here is the full code:



public class WinformsCaliburnBootstrapper<TViewModel> : BootstrapperBase where TViewModel : class


private UserControl rootView;

public WinformsCaliburnBootstrapper(ElementHost host)
: base(false)

this.rootView = new UserControl();
rootView.Loaded += rootView_Loaded;
host.Child = this.rootView;
Start();


void rootView_Loaded(object sender, RoutedEventArgs e)

DisplayRootViewFor<TViewModel>();


protected override object GetInstance(Type service, string key)

if (service == typeof(IWindowManager))

service = typeof(UserControlWindowManager<TViewModel>);
return new UserControlWindowManager<TViewModel>(rootView);

return Activator.CreateInstance(service);


private class UserControlWindowManager<TViewModel> : WindowManager where TViewModel : class

UserControl rootView;

public UserControlWindowManager(UserControl rootView)

this.rootView = rootView;


protected override Window CreateWindow(object rootModel, bool isDialog, object context, IDictionary<string, object> settings)

if (isDialog) //allow normal behavior for dialog windows.
return base.CreateWindow(rootModel, isDialog, context, settings);

rootView.Content = ViewLocator.LocateForModel(rootModel, null, context);
rootView.SetValue(View.IsGeneratedProperty, true);
ViewModelBinder.Bind(rootModel, rootView, context);
return null;


public override void ShowWindow(object rootModel, object context = null, IDictionary<string, object> settings = null)

CreateWindow(rootModel, false, context, settings); //.Show(); omitted on purpose





I hope this helps someone with the same needs. It sure saved me.






share|improve this answer






























    1














    Here are somethings you can start with



    • Create ViewModels and inherit them from PropertyChangedBase class provided by CM framework.

    • If required use the EventAggregator impelmentation for loosly coupled communication integration

    • Implement AppBootStrapper without the generic implementation which defines the root view model.

    Now you can use the view first approach and bind the view to model using the Bind.Model attached property on view. I have created a sample application to describe the approach here.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9088495%2fhow-to-use-caliburn-micro-in-a-winforms-app-with-one-wpf-form%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      6














      After much Googling and going through the Caliburn Micro source code, I've come up with an approach that works in a sample test application. I can't post the test application here for certain reasons, but here's the approach in a nutshell.



      • Create a WinForm with a button.

      • On button click, show a ChildWinForm


      • In the load handler of the ChildWinForm:




        // You'll need to reference WindowsFormsIntegration for the ElementHost class
        // ElementHost acts as the "intermediary" between WinForms and WPF once its Child
        // property is set to the WPF control. This is done in the Bootstrapper below.
        var elementHost = new ElementHostDock = DockStyle.Fill;
        Controls.Add(elementHost);
        new WpfControlViewBootstrapper(elementHost);


      • The bootstrapper above is something you'll have to write.


      • For more information about all it needs to do, see Customizing the Bootstrapper from the Caliburn Micro documentation.

      • For the purposes of this post, make it derive from the Caliburn Bootstrapper class.


      • It should do the following in its constructor:




        // Since this is a WinForms app with some WPF controls, there is no Application.
        // Supplying false in the base prevents Caliburn Micro from looking
        // for the Application and hooking up to Application.Startup
        protected WinFormsBootstrapper(ElementHost elementHost) : base(false)

        // container is your preferred DI container
        var rootViewModel = container.Resolve();
        // ViewLocator is a Caliburn class for mapping views to view models
        var rootView = ViewLocator.LocateForModel(rootViewModel, null, null);
        // Set elementHost child as mentioned earlier
        elementHost.Child = rootView;




      • Last thing to note is that you'll have to set the cal:Bind.Model dependency property in the XAML of WpfControlView.




        cal:Bind.Model="WpfControls.ViewModels.WpfControl1ViewModel"


      • The value of the dependency property is used passed as a string to Bootstrapper.GetInstance(Type serviceType, string key), which must then use it to resolve the WpfControlViewModel.


      • Since the container I use (Autofac), doesn't support string-only resolution, I chose to set the property to the fully qualified name of the view model. This name can then be converted to the type, and used to resolve from the container.





      share|improve this answer























      • You can use ViewModelBinder.Bind(rootViewModel, rootView, null); after ViewLocator.LocateForModel instead of cal:Bind.Model

        – Anders
        Jan 28 '14 at 14:40















      6














      After much Googling and going through the Caliburn Micro source code, I've come up with an approach that works in a sample test application. I can't post the test application here for certain reasons, but here's the approach in a nutshell.



      • Create a WinForm with a button.

      • On button click, show a ChildWinForm


      • In the load handler of the ChildWinForm:




        // You'll need to reference WindowsFormsIntegration for the ElementHost class
        // ElementHost acts as the "intermediary" between WinForms and WPF once its Child
        // property is set to the WPF control. This is done in the Bootstrapper below.
        var elementHost = new ElementHostDock = DockStyle.Fill;
        Controls.Add(elementHost);
        new WpfControlViewBootstrapper(elementHost);


      • The bootstrapper above is something you'll have to write.


      • For more information about all it needs to do, see Customizing the Bootstrapper from the Caliburn Micro documentation.

      • For the purposes of this post, make it derive from the Caliburn Bootstrapper class.


      • It should do the following in its constructor:




        // Since this is a WinForms app with some WPF controls, there is no Application.
        // Supplying false in the base prevents Caliburn Micro from looking
        // for the Application and hooking up to Application.Startup
        protected WinFormsBootstrapper(ElementHost elementHost) : base(false)

        // container is your preferred DI container
        var rootViewModel = container.Resolve();
        // ViewLocator is a Caliburn class for mapping views to view models
        var rootView = ViewLocator.LocateForModel(rootViewModel, null, null);
        // Set elementHost child as mentioned earlier
        elementHost.Child = rootView;




      • Last thing to note is that you'll have to set the cal:Bind.Model dependency property in the XAML of WpfControlView.




        cal:Bind.Model="WpfControls.ViewModels.WpfControl1ViewModel"


      • The value of the dependency property is used passed as a string to Bootstrapper.GetInstance(Type serviceType, string key), which must then use it to resolve the WpfControlViewModel.


      • Since the container I use (Autofac), doesn't support string-only resolution, I chose to set the property to the fully qualified name of the view model. This name can then be converted to the type, and used to resolve from the container.





      share|improve this answer























      • You can use ViewModelBinder.Bind(rootViewModel, rootView, null); after ViewLocator.LocateForModel instead of cal:Bind.Model

        – Anders
        Jan 28 '14 at 14:40













      6












      6








      6







      After much Googling and going through the Caliburn Micro source code, I've come up with an approach that works in a sample test application. I can't post the test application here for certain reasons, but here's the approach in a nutshell.



      • Create a WinForm with a button.

      • On button click, show a ChildWinForm


      • In the load handler of the ChildWinForm:




        // You'll need to reference WindowsFormsIntegration for the ElementHost class
        // ElementHost acts as the "intermediary" between WinForms and WPF once its Child
        // property is set to the WPF control. This is done in the Bootstrapper below.
        var elementHost = new ElementHostDock = DockStyle.Fill;
        Controls.Add(elementHost);
        new WpfControlViewBootstrapper(elementHost);


      • The bootstrapper above is something you'll have to write.


      • For more information about all it needs to do, see Customizing the Bootstrapper from the Caliburn Micro documentation.

      • For the purposes of this post, make it derive from the Caliburn Bootstrapper class.


      • It should do the following in its constructor:




        // Since this is a WinForms app with some WPF controls, there is no Application.
        // Supplying false in the base prevents Caliburn Micro from looking
        // for the Application and hooking up to Application.Startup
        protected WinFormsBootstrapper(ElementHost elementHost) : base(false)

        // container is your preferred DI container
        var rootViewModel = container.Resolve();
        // ViewLocator is a Caliburn class for mapping views to view models
        var rootView = ViewLocator.LocateForModel(rootViewModel, null, null);
        // Set elementHost child as mentioned earlier
        elementHost.Child = rootView;




      • Last thing to note is that you'll have to set the cal:Bind.Model dependency property in the XAML of WpfControlView.




        cal:Bind.Model="WpfControls.ViewModels.WpfControl1ViewModel"


      • The value of the dependency property is used passed as a string to Bootstrapper.GetInstance(Type serviceType, string key), which must then use it to resolve the WpfControlViewModel.


      • Since the container I use (Autofac), doesn't support string-only resolution, I chose to set the property to the fully qualified name of the view model. This name can then be converted to the type, and used to resolve from the container.





      share|improve this answer













      After much Googling and going through the Caliburn Micro source code, I've come up with an approach that works in a sample test application. I can't post the test application here for certain reasons, but here's the approach in a nutshell.



      • Create a WinForm with a button.

      • On button click, show a ChildWinForm


      • In the load handler of the ChildWinForm:




        // You'll need to reference WindowsFormsIntegration for the ElementHost class
        // ElementHost acts as the "intermediary" between WinForms and WPF once its Child
        // property is set to the WPF control. This is done in the Bootstrapper below.
        var elementHost = new ElementHostDock = DockStyle.Fill;
        Controls.Add(elementHost);
        new WpfControlViewBootstrapper(elementHost);


      • The bootstrapper above is something you'll have to write.


      • For more information about all it needs to do, see Customizing the Bootstrapper from the Caliburn Micro documentation.

      • For the purposes of this post, make it derive from the Caliburn Bootstrapper class.


      • It should do the following in its constructor:




        // Since this is a WinForms app with some WPF controls, there is no Application.
        // Supplying false in the base prevents Caliburn Micro from looking
        // for the Application and hooking up to Application.Startup
        protected WinFormsBootstrapper(ElementHost elementHost) : base(false)

        // container is your preferred DI container
        var rootViewModel = container.Resolve();
        // ViewLocator is a Caliburn class for mapping views to view models
        var rootView = ViewLocator.LocateForModel(rootViewModel, null, null);
        // Set elementHost child as mentioned earlier
        elementHost.Child = rootView;




      • Last thing to note is that you'll have to set the cal:Bind.Model dependency property in the XAML of WpfControlView.




        cal:Bind.Model="WpfControls.ViewModels.WpfControl1ViewModel"


      • The value of the dependency property is used passed as a string to Bootstrapper.GetInstance(Type serviceType, string key), which must then use it to resolve the WpfControlViewModel.


      • Since the container I use (Autofac), doesn't support string-only resolution, I chose to set the property to the fully qualified name of the view model. This name can then be converted to the type, and used to resolve from the container.






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Feb 2 '12 at 23:23









      ck.ck.

      6211023




      6211023












      • You can use ViewModelBinder.Bind(rootViewModel, rootView, null); after ViewLocator.LocateForModel instead of cal:Bind.Model

        – Anders
        Jan 28 '14 at 14:40

















      • You can use ViewModelBinder.Bind(rootViewModel, rootView, null); after ViewLocator.LocateForModel instead of cal:Bind.Model

        – Anders
        Jan 28 '14 at 14:40
















      You can use ViewModelBinder.Bind(rootViewModel, rootView, null); after ViewLocator.LocateForModel instead of cal:Bind.Model

      – Anders
      Jan 28 '14 at 14:40





      You can use ViewModelBinder.Bind(rootViewModel, rootView, null); after ViewLocator.LocateForModel instead of cal:Bind.Model

      – Anders
      Jan 28 '14 at 14:40













      2














      Following up on the accepted answer (good one!), I'd like to show you how to implement the WinForms Bootstrapper in a ViewModel First approach, in a way that:



      1. You won't have to create a WPF Window and,

      2. You won't have to bind directly to a ViewModel from within a View.

      For this we need to create our own version of WindowManager, make sure we do not call the Show method on the Window (if applicable to your case), and allow for the binding to occur.



      Here is the full code:



      public class WinformsCaliburnBootstrapper<TViewModel> : BootstrapperBase where TViewModel : class


      private UserControl rootView;

      public WinformsCaliburnBootstrapper(ElementHost host)
      : base(false)

      this.rootView = new UserControl();
      rootView.Loaded += rootView_Loaded;
      host.Child = this.rootView;
      Start();


      void rootView_Loaded(object sender, RoutedEventArgs e)

      DisplayRootViewFor<TViewModel>();


      protected override object GetInstance(Type service, string key)

      if (service == typeof(IWindowManager))

      service = typeof(UserControlWindowManager<TViewModel>);
      return new UserControlWindowManager<TViewModel>(rootView);

      return Activator.CreateInstance(service);


      private class UserControlWindowManager<TViewModel> : WindowManager where TViewModel : class

      UserControl rootView;

      public UserControlWindowManager(UserControl rootView)

      this.rootView = rootView;


      protected override Window CreateWindow(object rootModel, bool isDialog, object context, IDictionary<string, object> settings)

      if (isDialog) //allow normal behavior for dialog windows.
      return base.CreateWindow(rootModel, isDialog, context, settings);

      rootView.Content = ViewLocator.LocateForModel(rootModel, null, context);
      rootView.SetValue(View.IsGeneratedProperty, true);
      ViewModelBinder.Bind(rootModel, rootView, context);
      return null;


      public override void ShowWindow(object rootModel, object context = null, IDictionary<string, object> settings = null)

      CreateWindow(rootModel, false, context, settings); //.Show(); omitted on purpose





      I hope this helps someone with the same needs. It sure saved me.






      share|improve this answer



























        2














        Following up on the accepted answer (good one!), I'd like to show you how to implement the WinForms Bootstrapper in a ViewModel First approach, in a way that:



        1. You won't have to create a WPF Window and,

        2. You won't have to bind directly to a ViewModel from within a View.

        For this we need to create our own version of WindowManager, make sure we do not call the Show method on the Window (if applicable to your case), and allow for the binding to occur.



        Here is the full code:



        public class WinformsCaliburnBootstrapper<TViewModel> : BootstrapperBase where TViewModel : class


        private UserControl rootView;

        public WinformsCaliburnBootstrapper(ElementHost host)
        : base(false)

        this.rootView = new UserControl();
        rootView.Loaded += rootView_Loaded;
        host.Child = this.rootView;
        Start();


        void rootView_Loaded(object sender, RoutedEventArgs e)

        DisplayRootViewFor<TViewModel>();


        protected override object GetInstance(Type service, string key)

        if (service == typeof(IWindowManager))

        service = typeof(UserControlWindowManager<TViewModel>);
        return new UserControlWindowManager<TViewModel>(rootView);

        return Activator.CreateInstance(service);


        private class UserControlWindowManager<TViewModel> : WindowManager where TViewModel : class

        UserControl rootView;

        public UserControlWindowManager(UserControl rootView)

        this.rootView = rootView;


        protected override Window CreateWindow(object rootModel, bool isDialog, object context, IDictionary<string, object> settings)

        if (isDialog) //allow normal behavior for dialog windows.
        return base.CreateWindow(rootModel, isDialog, context, settings);

        rootView.Content = ViewLocator.LocateForModel(rootModel, null, context);
        rootView.SetValue(View.IsGeneratedProperty, true);
        ViewModelBinder.Bind(rootModel, rootView, context);
        return null;


        public override void ShowWindow(object rootModel, object context = null, IDictionary<string, object> settings = null)

        CreateWindow(rootModel, false, context, settings); //.Show(); omitted on purpose





        I hope this helps someone with the same needs. It sure saved me.






        share|improve this answer

























          2












          2








          2







          Following up on the accepted answer (good one!), I'd like to show you how to implement the WinForms Bootstrapper in a ViewModel First approach, in a way that:



          1. You won't have to create a WPF Window and,

          2. You won't have to bind directly to a ViewModel from within a View.

          For this we need to create our own version of WindowManager, make sure we do not call the Show method on the Window (if applicable to your case), and allow for the binding to occur.



          Here is the full code:



          public class WinformsCaliburnBootstrapper<TViewModel> : BootstrapperBase where TViewModel : class


          private UserControl rootView;

          public WinformsCaliburnBootstrapper(ElementHost host)
          : base(false)

          this.rootView = new UserControl();
          rootView.Loaded += rootView_Loaded;
          host.Child = this.rootView;
          Start();


          void rootView_Loaded(object sender, RoutedEventArgs e)

          DisplayRootViewFor<TViewModel>();


          protected override object GetInstance(Type service, string key)

          if (service == typeof(IWindowManager))

          service = typeof(UserControlWindowManager<TViewModel>);
          return new UserControlWindowManager<TViewModel>(rootView);

          return Activator.CreateInstance(service);


          private class UserControlWindowManager<TViewModel> : WindowManager where TViewModel : class

          UserControl rootView;

          public UserControlWindowManager(UserControl rootView)

          this.rootView = rootView;


          protected override Window CreateWindow(object rootModel, bool isDialog, object context, IDictionary<string, object> settings)

          if (isDialog) //allow normal behavior for dialog windows.
          return base.CreateWindow(rootModel, isDialog, context, settings);

          rootView.Content = ViewLocator.LocateForModel(rootModel, null, context);
          rootView.SetValue(View.IsGeneratedProperty, true);
          ViewModelBinder.Bind(rootModel, rootView, context);
          return null;


          public override void ShowWindow(object rootModel, object context = null, IDictionary<string, object> settings = null)

          CreateWindow(rootModel, false, context, settings); //.Show(); omitted on purpose





          I hope this helps someone with the same needs. It sure saved me.






          share|improve this answer













          Following up on the accepted answer (good one!), I'd like to show you how to implement the WinForms Bootstrapper in a ViewModel First approach, in a way that:



          1. You won't have to create a WPF Window and,

          2. You won't have to bind directly to a ViewModel from within a View.

          For this we need to create our own version of WindowManager, make sure we do not call the Show method on the Window (if applicable to your case), and allow for the binding to occur.



          Here is the full code:



          public class WinformsCaliburnBootstrapper<TViewModel> : BootstrapperBase where TViewModel : class


          private UserControl rootView;

          public WinformsCaliburnBootstrapper(ElementHost host)
          : base(false)

          this.rootView = new UserControl();
          rootView.Loaded += rootView_Loaded;
          host.Child = this.rootView;
          Start();


          void rootView_Loaded(object sender, RoutedEventArgs e)

          DisplayRootViewFor<TViewModel>();


          protected override object GetInstance(Type service, string key)

          if (service == typeof(IWindowManager))

          service = typeof(UserControlWindowManager<TViewModel>);
          return new UserControlWindowManager<TViewModel>(rootView);

          return Activator.CreateInstance(service);


          private class UserControlWindowManager<TViewModel> : WindowManager where TViewModel : class

          UserControl rootView;

          public UserControlWindowManager(UserControl rootView)

          this.rootView = rootView;


          protected override Window CreateWindow(object rootModel, bool isDialog, object context, IDictionary<string, object> settings)

          if (isDialog) //allow normal behavior for dialog windows.
          return base.CreateWindow(rootModel, isDialog, context, settings);

          rootView.Content = ViewLocator.LocateForModel(rootModel, null, context);
          rootView.SetValue(View.IsGeneratedProperty, true);
          ViewModelBinder.Bind(rootModel, rootView, context);
          return null;


          public override void ShowWindow(object rootModel, object context = null, IDictionary<string, object> settings = null)

          CreateWindow(rootModel, false, context, settings); //.Show(); omitted on purpose





          I hope this helps someone with the same needs. It sure saved me.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 5 '13 at 8:01









          Jony AdamitJony Adamit

          1,9652134




          1,9652134





















              1














              Here are somethings you can start with



              • Create ViewModels and inherit them from PropertyChangedBase class provided by CM framework.

              • If required use the EventAggregator impelmentation for loosly coupled communication integration

              • Implement AppBootStrapper without the generic implementation which defines the root view model.

              Now you can use the view first approach and bind the view to model using the Bind.Model attached property on view. I have created a sample application to describe the approach here.






              share|improve this answer



























                1














                Here are somethings you can start with



                • Create ViewModels and inherit them from PropertyChangedBase class provided by CM framework.

                • If required use the EventAggregator impelmentation for loosly coupled communication integration

                • Implement AppBootStrapper without the generic implementation which defines the root view model.

                Now you can use the view first approach and bind the view to model using the Bind.Model attached property on view. I have created a sample application to describe the approach here.






                share|improve this answer

























                  1












                  1








                  1







                  Here are somethings you can start with



                  • Create ViewModels and inherit them from PropertyChangedBase class provided by CM framework.

                  • If required use the EventAggregator impelmentation for loosly coupled communication integration

                  • Implement AppBootStrapper without the generic implementation which defines the root view model.

                  Now you can use the view first approach and bind the view to model using the Bind.Model attached property on view. I have created a sample application to describe the approach here.






                  share|improve this answer













                  Here are somethings you can start with



                  • Create ViewModels and inherit them from PropertyChangedBase class provided by CM framework.

                  • If required use the EventAggregator impelmentation for loosly coupled communication integration

                  • Implement AppBootStrapper without the generic implementation which defines the root view model.

                  Now you can use the view first approach and bind the view to model using the Bind.Model attached property on view. I have created a sample application to describe the approach here.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 2 '12 at 12:19









                  ChandermaniChandermani

                  41.1k117686




                  41.1k117686



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9088495%2fhow-to-use-caliburn-micro-in-a-winforms-app-with-one-wpf-form%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현