如何创建支持暗和亮主题的画笔?

Adi*_*be7 3 silverlight themes windows-phone-7

我正在使用WP7,我想创建一个自定义画笔(作为本地资源),使用不同颜色的黑暗和浅色主题(对于instace,如果主题为黑色则为红色,如果为白色则为蓝色).

我该怎么做?

谢谢!

Ric*_*lay 5

集成/系统画笔不会根据主题更改其属性,根据当前主题包含不同的画笔集.你可以看到它的各种版本%programfiles%\Microsoft SDKs\Windows Phone\v7.1\Design

我写了一个以完全相同的方式实现主题支持的自定义ResourceDictionary:通过根据明/暗主题加载适当的主题词典.

这是一个使用它的示例.它适用于Visual Studio设计器和Blend,但不支持Blend中的白色主题预览,因为Blend以无法再现的方式加载资源.

<Application.Resources>
    <custom:ThemeResourceDictionary>
        <custom:ThemeResourceDictionary.LightResources>
            <ResourceDictionary Source="/ThemeManagement;component/Resources/Light.xaml" />
        </custom:ThemeResourceDictionary.LightResources>
        <custom:ThemeResourceDictionary.DarkResources>
            <ResourceDictionary Source="/ThemeManagement;component/Resources/Dark.xaml" />
        </custom:ThemeResourceDictionary.DarkResources>
    </custom:ThemeResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

上面的代码从两个不同的文件加载资源,但它们可以像任何其他ResourceDictionary一样容易地内联声明.

ThemeResourceDictionary我的原始博客文章中提供了源代码,但是在我的博客崩溃的情况下,它也会出现在不同的Stack Overflow问题上.