开发者

Best way to set WPF styles so they apply to all WPF components in a WinForms application

开发者 https://www.devze.com 2023-03-02 01:44 出处:网络
Following on from this question about setting Culture, I have a similar issue with application-wide styles.

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 exa开发者_C百科ct duplicate.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号