C# WPF Designer Exception: animation object cannot be used to animate property 'Foreground' [duplicate]

痴心易碎 提交于 2019-12-05 23:03:43

问题


The following code runs and works perfectly at runtime but crashes the designer and I have NO idea why.

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

That crashes the designer with the following error:

'System.Windows.Media.Animation.ColorAnimationUsingKeyFrames' animation object cannot be used to animate property 'Foreground' because it is of incompatible type 'System.Windows.Media.Brush'

I have been trying to figure this out for hours now and I just have no idea why this crashing the designer considering this example is shown many times online and works at run-time.

Can anyone please tell me what I am doing wrong?

Thanks!


回答1:


You might have to use this syntax:

Storyboard.TargetProperty="(TextBlock.Foreground).Color"

"Foreground" and "SolidColorBrush" are the same object.



来源:https://stackoverflow.com/questions/17079072/c-sharp-wpf-designer-exception-animation-object-cannot-be-used-to-animate-prope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!