开发者

Problem with custom window class accessing resources in another assembly

My first foray into WPF has been creating an applcation (ABC) and a solution of class libraries (XYZ) that will be used on all future applications.

In order to reuse the window from ABC so all applications have a consistent look and feel, I've created a base class that inherits from System.Windows.Window. This class resides in the XYZWindows class library project in namespace XYZ.Windows. I also have a class library project called XYZResources that contains (at present) two themed skins comprised of dozens of styles.

In application ABC I was able to reference these skins via code in App.xaml:

public void ApplySkin( ThemedSkin Skin ) {
    Collection<ResourceDictionary> merged = base.Resources.MergedDictionaries;

    switch( Skin ) {
        case ThemedSkin.Dark:
            merged[0].Source = new Uri( "pack://application:,,,/XYZResources;component/Themes/Dark.xaml", UriKind.Absolute );
        case ThemedSkin.Light:
            merged[0].Source = new Uri( "pack://application:,,,/XYZResources;component/Themes/Light.xaml", UriKind.Absolute );
    }
}

Being new to WPF, I'm not sure where I found this but it worked and I was able to globally style all controls as well as reference individual styles in XAML using {Dynamic Resource}. Bec开发者_JAVA百科ause my window class is my first attempt at creating a window strictly in code, I'm not sure how to access my styles.

I've tinkered with ComponentResourceKey, but I haven't figured out what type I need to use in its constructor.

I need a really good tutorial or at least a push in the right direction, but this kind of stuff is really difficult to Google successfully.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜