2013-10-08 132 views
2

我有一个具有边框的用户控件,边框的颜色应设置为依赖属性。我也想动画边框的不透明度。我目前的XAML代码如下所示:无法解析属性路径中的所有属性引用

<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> 

此只给出错误:

Cannot resolve all property references in the property path 'BorderBrush.Opacity'. Verify that applicable objects support the properties.

但是,如果我换到BorderBrush的颜色,可以说Black它的工作原理。这是如何实现的?我想通过依赖项属性设置我的边界的刷子颜色。是的,依赖属性是Brush

+1

您是否为DependencyProperty设置了默认画笔?如果不是默认值是空的并且会导致这样的错误。 – LPL

+0

@LPL我怎样才能做到这一点? –

回答

2

我觉得这里的问题是,如果有一个对象(刷)动画动画才起作用。如果你注册你的DependencyProperty没有默认值,它默认为空。请尝试用默认值

public static readonly DependencyProperty NotificationColorProperty = DependencyProperty.Register(
    "NotificationColor", 
    typeof(Brush), 
    typeof(ImageViewerUserControl), 
    new PropertyMetadata(Brushes.Transparent) 
); 

编辑注册DP:

正如@Sheridan说使用Storyboard.TargetProperty="Opacity"代替Border.Opacity。尽管如果你指定了一个直接的BorderBrush它可以工作,但它对于我来说并不适用于一个有界的DP。

+0

听起来像解决方案,但:我得到此错误消息:默认值类型不匹配属性的类型'NotificationColor'。 –

+0

什么类型是NotificationColor?刷子还是颜色? – LPL

+0

感谢您的输入,但在运行时弹出相同的错误消息。该物业是刷机。 –

1

AnimatedBorderBrush名称是一种误导,因为它涉及到一个Border一个BorderBrush。如果你想动画Border.Opacity,然后在DoubleAnimation代替BorderBrush.Opacity使用Border.Opacity

<DoubleAnimation Storyboard.TargetName="AnimatedBorderBrush" 
    Storyboard.TargetProperty="Border.Opacity" 
    RepeatBehavior="Forever" 
    AutoReverse="True" 
    From="1" 
    To="0.0" 
    Duration="0:0:1" /> 

UPDATE >>>

AHHHHH,是我不好......随着动画的Border中定义的,有没有必要引用它,只要使用Opacity

<DoubleAnimation Storyboard.TargetName="AnimatedBorderBrush" 
    Storyboard.TargetProperty="Opacity" 
    RepeatBehavior="Forever" 
    AutoReverse="True" 
    From="1" 
    To="0.0" 
    Duration="0:0:1" /> 
+0

我可以看到你的命名规则是什么意思,我尝试了你的建议,但没有运气。 –

+0

你的回答是正确的,但问题是,在这里的家伙也“固定”我的问题..谢谢很多! –

+1

完全没有问题。 – Sheridan

相关问题