可以弄清楚这一点,我在aaplication.xaml中有一些静态资源
这些静态资源我根据设计在不同的地方使用。现在我想在故事板中使用静态资源来制作彩色动画,但我无法让它工作,我收到错误:An object of the type "System.Windows.Media.SolidColorBrush" cannot be applied to a property that expects the type "System.Nullable1[[System.Windows.Media.Color,....]]
到目前为止的代码:
应用程序.XAML
<Application.Resources>
<SolidColorBrush x:Key="GreenLight" Color="#0CAF12" />
</Application.Resources>
在用户控件标签样式中:
<Setter Property="Label.Content" Value="Connected" />
<DataTrigger.EnterActions>
<BeginStoryboard Name="StoryConnected">
<Storyboard Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)">
<ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" To="{StaticResource GreenLight}" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="StoryConnected" />
</DataTrigger.ExitActions>
这不起作用,因为绑定To
属性时无法冻结Storyboard
:
To="{Binding Color, Source={StaticResource GreenLight}}"
所以你实际上需要将To
属性设置为一个Color
对象,即像这样定义你的资源:
<Color x:Key="GreenLight">#0CAF12</Color>