2

Following on from this question about setting Culture, I have a similar issue with application-wide styles.

In a pure WPF application, I can set these up in App.xaml.

However I have a WinForms application that is being progressively migrated to WPF, and contains several WPF UserControls. Is there a way to define application-wide styles that will be applied to all these components?

** UPDATE **

Voted to close this after finding an exact duplicate.

The blog post linked from the duplicate discusses several options including adding an App class with build action = Page.

Community
  • 1
  • 1
Joe
  • 122,218
  • 32
  • 205
  • 338
  • possible duplicate of [WPF control not displaying in ElementHost in WinForms app](http://stackoverflow.com/questions/4326621/wpf-control-not-displaying-in-elementhost-in-winforms-app) – Joe Apr 30 '11 at 09:14

1 Answers1

1

Different question, similar answer. By deriving from ElementHost you can control the resources of all elements introduced into your WinForms application. In the simplest case you can have an App.xaml as an ordinary resource dictionary and then when the ElementHost child is set you can set its resources to the resource dictionary. If the child element has resources of its own then you can set the child's resources to a new merged dictionary consisting of its existing resources and the resource dictionary representing the application resources.

By dynamically modifying the resources of elements as they are added to your application, you can simulate the effect of application resources with a resource dictionary that is searched after all other element-based resources.

Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
  • Thanks, I'll look at that approach. Does it mean the App.Xaml dictionary will be duplicated for every ElementHost in the application? – Joe Apr 29 '11 at 18:20
  • No, merged dictionaries don't copy the dictionaries they merge, so as long as you only load App.xaml once and save it in a static field, there will only be one copy. – Rick Sladkey Apr 29 '11 at 19:11