2

I have a winforms app but I would like to introduce a WPF user control into the app as a taster for further WPF implementation.

This control needs to receive from its Host a single piece of information, a string. How can I pass this down from the Winforms app to the hosted control?

Or, indeed, can I?

2 Answers 2

5

Assign properties of wpf control after creating an instance and before giving the reference to host's childes

WpfUserControl ctrl = new WpfUserControl();
ctrl.Data = passedData;
ElementHost1.Child = ctrl;
3
  • This also looks pretty good, but not right for my usage scenario at present. However it could one day be a life saver.
    – One Monkey
    Oct 21, 2009 at 13:30
  • Why doesn't this match your scenario? Oct 21, 2009 at 15:27
  • My control was not dynamically added, it was already on the form. The other answer is now in use and works beautifully. In fact, if I were to dynamically add the control I would probably give the control settable properties as the chosen answer recommends.
    – One Monkey
    Oct 22, 2009 at 10:57
2

It is possible. Extend your WPF User Control with methods to set whatever data you want and call them from within WinForms application. See this article for example.

1
  • Looks helpful. Will try this.
    – One Monkey
    Oct 21, 2009 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.