WPF control not displaying in ElementHost in WinForms app

后端 未结 1 1862
心在旅途
心在旅途 2020-12-17 18:53

I have a problem with a WPF control that I\'m trying to host in an ElementHost in a WinForms app. The control is a lookless custom control that I originally developed in a s

1条回答
  •  佛祖请我去吃肉
    2020-12-17 19:29

    Thanks for replying, but I think you may misunderstand me: I'm trying to use a custom element, whose resources are normally in the Application object, not insert the application itself into the ElementHost.

    Fortunately, I've found an answer:

    http://drwpf.com/blog/2007/10/05/managing-application-resources-when-wpf-is-hosted/

    Short version:

    • Set build action for App.xaml to Page
    • In the code behind for App.xaml create a default constructor that just calls InitializeComponent()
    • When the WinForms app starts up, just create an instance of the App class.

    And then it's all good: my WPF control appears as it should.

    Now, why is it I only find the answer after I've posted to StackOverflow?

    Thanks again,

    Bart

    0 讨论(0)
提交回复
热议问题