chillitom
chillitom

Reputation: 25676

WPF used within a WinForms application, where to put Application resources?

At present we host a number of WPF controls in a WinForms application. The application is started using the System.Windows.Forms.Application.Run(...) method and WPF controls hosted using the ElementHost.

In a normal WPF application I'd define a System.Windows.Application object (App.xaml) and call run on it. Normally any application level WPF resources would go in there. We don't have this.

How can I specify application level resources for the WPF controls but still run as a WinForms app?

Upvotes: 17

Views: 7298

Answers (2)

Christian Moser
Christian Moser

Reputation: 1951

If you host WPF controls within a WinForms application you do not have the Applicationobject which hosts the application-wide resources. The trick is to create such a object, load your global resources and merge them into the ResourceDictionary.

Here is an example of this code:

http://www.snippetsource.net/Snippet/26/load-application-level-resources-in-winforms-hosted-wpf-controls (Link fixed)

Upvotes: -2

benPearce
benPearce

Reputation: 38333

In a hosted environment you do not have easy access to the Application, Dr WPF has a couple of methods for working in a hosted scenario at http://drwpf.com/blog/2007/10/05/managing-application-resources-when-wpf-is-hosted/.

I am personally using his SharedResources class in a work project, VB6 Form hosting Winforms UserControl hosting ElementHost hosting WPF UserControl with a Application wide theme, for the WPF controls.

Upvotes: 14

Related Questions