Assembly-wide / root-level styles in WPF class library

后端 未结 7 1988
夕颜
夕颜 2021-01-30 06:28

I have a C# (2008/.NET 3.5) class library assembly that supports WPF (based on this article).
I\'ve created several windows, and am now attempting to create a common style

7条回答
  •  走了就别回头了
    2021-01-30 07:24

    If you dont have an app.xaml, you can still load it into the appplication-level resources, but you have to write code (not xaml) to do it, similar to this...

    void LoadIt()
    {
         ResourceDictionary MyResourceDictionary = new ResourceDictionary();
         MyResourceDictionary.Source = new Uri("MyResources.xaml", UriKind.Relative);
         App.Current.Resources.MergedDictionaries.Add(  MyResourceDictionary )
    }
    

    check out this site for an example: http://ascendedguard.com/2007/08/one-of-nice-features-about-wpf-is-how.html

提交回复
热议问题