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

后端 未结 7 2125
夕颜
夕颜 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:07

    Dr. WPF (or the person formerly known as Dr. WPF) has a great post on the subject.

    Here's an excerpt from the post where they create the Application object and add resources:

    if (Application.Current == null)
    {
        // create the Application object
        new Application();
    
        // merge in your application resources
        Application.Current.Resources.MergedDictionaries.Add(
            Application.LoadComponent(
                new Uri("MyLibrary;component/Resources/MyResourceDictionary.xaml",
                UriKind.Relative)) as ResourceDictionary);
    }
    

    Since my assembly is hosted via interop I had to add setting the ShutdownMode as follows and shutdown when finished:

    new Application() { ShutdownMode = ShutdownMode.OnExplicitShutdown };
    

    It worked like a charm.

提交回复
热议问题