我有一本这样的资源字典:
<ResourceDictionary>
<SolidColorBrush x:Key="SpecialColor" Color="Yellow" />
<DataTemplate x:Key="SpecialTemplate">
<Rectangle Fill="{StaticResource SpecialColor}" />
</DataTemplate>
</ResourceDictionary>我将资源字典添加到页面中,如下所示:
<Page.Resources>
<ResourceDictionary Source="ms-appx:///Style/Special.xaml" />
</Page.Resources>我这样使用SpecialRectangle:
<ContentPresenter ContentTemplate="{StaticResource SpecialTemplate}" />问:我该如何改变颜色?
更新--我试过了,但它对我不起作用:
<Page.Resources>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Style/Special.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="SpecialColor" Color="Red" />
</Page.Resources>这也不起作用:
<Page.Resources>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Style/Special.xaml" />
<ResourceDictionary>
<SolidColorBrush x:Key="SpecialColor" Color="Red" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</Page.Resources>谢谢。
发布于 2014-08-22 16:04:46
取决于条件,您有许多选择--主要是
ContentPresenter在哪里,如果perf更重要,或者开发人员的方便/清晰的体系结构更重要。您可以使用模板选择器并使用两个模板而不是一个模板,您可以绑定矩形的Fill,您可以使用VisualStateManager,如果您在ListView中想要在没有绑定的情况下获得最佳性能,您可以使用CCC事件,您也可以简单地遍历可视树并惹恼几个人。:)
https://stackoverflow.com/questions/25451012
复制相似问题