none
Hosting a WPF Composite Control in Windows Forms RRS feed

  • Question

  • Hi

    I want to host my WPF application in Windows Forms and I have some questions in that regard. My WPF app has two forms that I want to make available for WinForms. So:

    1) Do I have to create two user controls of the WPF app first?

    2) Do I need to have some public methods for the WinForm to call to make one or the other Form to show?

    The logic is something like this: The WinForm loads the DLL (WPF/my dll) and to show View1 it has to call a public method in the DLL, right?

    MyWPFApp.ShowView1(params);

    MyWPFApp.ShowView2(params);

    3) I want to send inn some data to the WPF-views, as can be seen by the above example, how is this done? Can it be done like above?

    Do I have to tag some methods and events with attributes to make them visible for the WinForm? ComVisible etc? Examples?

    Thanks in advance.

    Tuesday, November 30, 2010 1:01 PM

Answers

  • Hi NorwegianEcho,

    First we don't have form in WPF, I wonder do you mean the WPF window instead?

    For hosting WPF control in Winform application, here is a MSDN walkthrough article at http://msdn.microsoft.com/en-us/library/ms742215.aspx you may refer to it for more information and a complete code sample.

    As to your questions,

    1) Yes you may create two user controls, however if you are able to integrate them into one control you may not bother to create them separately.  For instance, a TabControl holds one Frame in each TabItem of it.

    2) InitializeComponent method is implemented in WPF side, and after you hosting the user control into winform, they will show themselves up. If you are going to control the visibility of them, please try to access the Visibility Property.

    3) Like in the article referred above, you may write your own EventArgs derived class used to pass in any parameters.

    Hope it helps! If you still have any doubts or questions please feel free to let me know.

     

    Best regards,

    Yves


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Thursday, December 2, 2010 6:43 AM
    Moderator

All replies

  • Hi NorwegianEcho,

    First we don't have form in WPF, I wonder do you mean the WPF window instead?

    For hosting WPF control in Winform application, here is a MSDN walkthrough article at http://msdn.microsoft.com/en-us/library/ms742215.aspx you may refer to it for more information and a complete code sample.

    As to your questions,

    1) Yes you may create two user controls, however if you are able to integrate them into one control you may not bother to create them separately.  For instance, a TabControl holds one Frame in each TabItem of it.

    2) InitializeComponent method is implemented in WPF side, and after you hosting the user control into winform, they will show themselves up. If you are going to control the visibility of them, please try to access the Visibility Property.

    3) Like in the article referred above, you may write your own EventArgs derived class used to pass in any parameters.

    Hope it helps! If you still have any doubts or questions please feel free to let me know.

     

    Best regards,

    Yves


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Thursday, December 2, 2010 6:43 AM
    Moderator
  • Hi NorwegianEcho,

    We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.

     

    Best regards,

    Yves


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Tuesday, December 7, 2010 3:42 AM
    Moderator