我有一个 CustomControl 库,其控件定义如下:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCustomControlLibrary1">
<SolidColorBrush x:Key="Test"
Color="Red" />
<Style TargetType="{x:Type local:CustomControl1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
<Border Background="{StaticResource Test}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
哪个工作正常。
但是,如果我将“StaticResource”更改为“DynamicResource”,红色不再拾取?
为什么是这样?