【发布时间】:2015-10-06 14:46:36
【问题描述】:
我有一个 WPF 画布项目,我从工具箱中将对象拖放到画布上。根据某些数据,其中一些对象应该闪烁或闪烁。我得到一个未处理的异常:Cannot animate '(Foreground).(0)' on an immutable object instance.. 以下是我的代码。有人建议使用 (Foreground).(SolidColorBrush.Color) 并且我在我的标记中更改了它,但它似乎并没有解决它。
<!-- DataTemplate for DesignerCanvas look and feel -->
<DataTemplate DataType="{x:Type viewModels:SingleValueControlViewModel}">
<Grid>
<Label Name="label" Content="{Binding TagValue}" IsHitTestVisible="False" Height="{Binding ItemHeight}" Width="{Binding ItemWidth}"
Background="{Binding BackColor}"
Foreground="{Binding ForeColor}"
BorderBrush="{Binding BorderColor}"
BorderThickness="{Binding StyleProperties.BorderWidth}"
FontFamily="{Binding StyleProperties.Font.FontFamily}"
FontSize = "{Binding StyleProperties.Font.Size}"
FontStyle="{Binding StyleProperties.Font.Style}"
HorizontalContentAlignment="{Binding TextAlign}" >
<Label.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding StyleProperties.FlashEnable}" Value="true">
<Setter Property="Label.Background" Value="Black"></Setter>
<Setter Property="Label.Foreground" Value="Red"></Setter>
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<ColorAnimation
Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)"
Duration="00:00:00:01"
From="Black" To="Red">
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Grid>
</DataTemplate>
【问题讨论】:
-
闪存? '其中一些对象应该闪烁'是什么意思。这些对象会包含 Flash 电影吗?还是它们会像发光等一样看起来不同。
-
请贴出相关代码
-
@user3798700 我明白你的意思,将发布答案,正在努力。
-
@AnjumSKhan 我用更新的代码和错误消息修改了我的原始问题。