我正在尝试在Windows Phone 7中创建自定义应用程序主题,但遗憾的是遇到了以下问题:如果我尝试更改样式和某些默认颜色,结果样式正确应用但是某些原因颜色不是。我的意思是我的新Style使用默认颜色而不是自定义颜色。
这是我正在做的事情:
1.我创建了一个名为CustomTheme的文件夹,其中包含两个ResourceDictionaries:
Brushes.xaml
Styles.xaml
2.接下来我以这种方式将它们添加到App.xaml中:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CustomTheme/Brushes.xaml"/>
<ResourceDictionary Source="CustomTheme/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
3。之后我尝试以这种方式使用Styles.xaml中的样式:
<TextBox Style="{StaticResource SomeStyle}"/>
4.结果Style按预期应用(我的意思是ControlTemplate已更改),但使用默认颜色而不是 Brushes.xaml
中指定的颜色我设法通过在Styles.xaml文件而不是App.xaml中添加Brushes.xaml来找到问题的解决方法:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Brushes.xaml"/>
</ResourceDictionary.MergedDictionaries>
我要求提出建议。这个问题有更好的解决方案吗?为什么颜色没有正确合并?
答案 0 :(得分:1)
你所拥有的解决方案是我所知道的最好的解决方案,也是我们在实现RunKeeper时所使用的解决方案,尽管我们也在App.xaml中保留了相同的Brushes.xaml。
老实说感觉“破碎”,但至少有一个可用的解决方法:)