Wpf 无法解析propertypath中的所有属性引用
我有一个带边框的UserControl,边框的颜色应该用依赖属性设置。我还想设置边框不透明度的动画。我当前的xaml代码如下所示:Wpf 无法解析propertypath中的所有属性引用,wpf,Wpf,我有一个带边框的UserControl,边框的颜色应该用依赖属性设置。我还想设置边框不透明度的动画。我当前的xaml代码如下所示: <Border BorderBrush="{Binding ElementName=ImageViewerUserControl, Path=NotificationColor}" BorderThickness="3" x:Name="AnimatedBorderBrush" Visibility="{Binding ElementNa
<Border BorderBrush="{Binding ElementName=ImageViewerUserControl,
Path=NotificationColor}" BorderThickness="3" x:Name="AnimatedBorderBrush"
Visibility="{Binding ElementName=ImageViewerUserControl,
Path=ShowSequenceErrorNotification, Converter={StaticResource boolToVisibility}}">
<Border.Triggers>
<EventTrigger RoutedEvent="Border.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="AnimatedBorderBrush"
Storyboard.TargetProperty="BorderBrush.Opacity"
RepeatBehavior="Forever"
AutoReverse="True"
From="1"
To="0.0"
Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
</Border>
这只会导致以下错误:
无法解析属性路径“BorderBrush.Opacity”中的所有属性引用。验证适用对象是否支持这些属性
但如果我将边框笔刷的颜色改为,就说
Black
它可以工作。这怎么可能实现呢?我想通过依赖属性设置边框的笔刷颜色。是的,依赖项属性是一个画笔
您的动画边界画笔
名称具有误导性,因为它与边界
相关,而不是边界画笔
。如果要设置Border.Opacity
的动画,请在DoubleAnimation
中使用Border.Opacity
,而不是BorderBrush.Opacity
:
<DoubleAnimation Storyboard.TargetName="AnimatedBorderBrush"
Storyboard.TargetProperty="Border.Opacity"
RepeatBehavior="Forever"
AutoReverse="True"
From="1"
To="0.0"
Duration="0:0:1" />
<DoubleAnimation Storyboard.TargetName="AnimatedBorderBrush"
Storyboard.TargetProperty="Opacity"
RepeatBehavior="Forever"
AutoReverse="True"
From="1"
To="0.0"
Duration="0:0:1" />
我认为这里的问题是,只有当有一个对象(画笔)要设置动画时,动画才会工作。如果您注册的
DependencyProperty
没有默认值,则默认为空。请尝试使用默认值注册DP
public static readonly DependencyProperty NotificationColorProperty = DependencyProperty.Register(
"NotificationColor",
typeof(Brush),
typeof(ImageViewerUserControl),
new PropertyMetadata(Brushes.Transparent)
);
编辑:
正如@Sheridan所说,使用
Storyboard.TargetProperty=“Opacity”
而不是Border.Opacity
。尽管在指定直接边界笔刷时它可以工作,但在有边界DP的情况下它对我不起作用。是否为DependencyProperty设置了默认笔刷?如果not默认值为null,将导致这样的错误。@LPL我如何才能做到这一点?我知道你的命名约定是什么意思,我尝试了你的建议,但没有成功。你的答案是正确的,但问题是这里的人也“修复”了我的问题。。非常感谢!一点问题也没有。听起来像是解决方案,但:我收到了以下错误消息:默认值类型与属性“NotificationColor”的类型不匹配。NotificationColor是什么类型?画笔还是颜色?谢谢您的输入,但在运行时会弹出相同的错误消息。财产是刷子,耶稣。它只是名称空间。