我在Brushes.xaml中有这个:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:SkinBox.Controls">
<SolidColorBrush x:Key="{x:Static controls:Keys.BackgroundBrushKey}"
Color="{DynamicResource {x:Static controls:Keys.BackgroundColorKey}}" />
</ResourceDictionary>
并在Generic.xaml中像这样使用它:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SkinBox.Controls"
xmlns:system="clr-namespace:System;assembly=System">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Skins/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
问题是wpf冻结了笔刷,因此
DynamicResource
没有任何作用。有没有解决此问题的干净方法?我只能想到讨厌的骇客。
最佳答案
解决方法的想法:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:SkinBox.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Skins/Yellow.Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/SkinBox.Controls;component/Themes/Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
这仍然不能提供真正的动态资源,但是会重新应用画笔,以便在应用皮肤时更新画笔。
无需在每个皮肤上复制画笔。
关于wpf - 是否有办法使ResourceDictionary中的Freezable动态化DynamicResource?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33242667/