C#WPF Designer异常:动画对象不能用于动画属性'Foreground'

Lan*_*ens 7 c# wpf animation exception wpf-4.0

以下代码在运行时运行并完美运行,但崩溃了设计器,我不明白为什么.

<VisualState x:Name="Selected" >
    <Storyboard>
        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="HeaderTopSelected">
            <EasingColorKeyFrame KeyTime="0" Value="White"/>
        </ColorAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>
Run Code Online (Sandbox Code Playgroud)

这会使设计器崩溃,并出现以下错误:

'System.Windows.Media.Animation.ColorAnimationUsingKeyFrames'动画对象不能用于动画属性'Foreground',因为它是不兼容的类型'System.Windows.Media.Brush'

我一直试图解决这个问题几个小时,我只是不知道为什么这个崩溃设计师考虑到这个例子在网上很多次显示并在运行时工作.

谁能告诉我我做错了什么?

谢谢!

Ter*_*rry 17

您可能必须使用以下语法:

Storyboard.TargetProperty="(TextBlock.Foreground).Color"
Run Code Online (Sandbox Code Playgroud)

"Foreground"和"SolidColorBrush"是同一个对象.

  • 特里,我不在乎社会还没有完全接受我对你的爱.我仍然会从屋顶喊出来.+1. (2认同)