C# WPF 设计器异常 : animation object cannot be used to animate property 'Foreground'

标签 c# wpf exception animation 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>

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

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

几个小时以来,我一直在努力解决这个问题,我只是不知道为什么考虑到这个例子在网上多次显示并在运行时工作,这会让设计人员崩溃。

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

谢谢!

最佳答案

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

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

“前景”和“SolidColorBrush”是同一个对象。

关于C# WPF 设计器异常 : animation object cannot be used to animate property 'Foreground' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17079072/

相关文章:

.NET 4.0 WPF 自动化异常

c# - 多个可能的异常的单个异常处理程序

c# - Java 是否像 C# 一样具有 'Debug' 和 'Release' 构建模式?

c# - WPF MVVM 更改模型

python - 处理 View 语法错误与 Django 中的异常

wpf - 如何在 WPF 中创建环绕按钮

c# - ListView:从 ListViewItem 获取实际的项目对象

c# - 这如何不导致堆栈溢出?

c# - 在 MSBuild 的解决方案中循环项目

c# - Initializer List 和 Constructor 函数调用顺序