'[Unknown]'属性不指向路径中的DependencyObject

时间:2014-03-26 09:09:20

标签: wpf animation binding storyboard

我在边框上有动画

<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="Border">
    <EasingColorKeyFrame KeyTime="0" Value="#FF5E5E5E"/>
</ColorAnimationUsingKeyFrames>

它在运行时有效。

但在设计时我收到以下错误:

'[Unknown]' property does not point to a DependencyObject in path '(0).(1)[1].(2)'.

有人可以向我解释这意味着什么吗?

修改

动画的使用在控制模板中:

<ControlTemplate x:Key="GrayButtonTemplate" TargetType="{x:Type ButtonBase}">
        <Border 
            x:Name="Border"  
            CornerRadius="0" 
            BorderThickness="1">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="White" Offset="0"/>
                    <GradientStop Color="White" Offset="0.9"/>
                </LinearGradientBrush>
            </Border.Background>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="Border">
                                <EasingColorKeyFrame KeyTime="0" Value="#FF5E5E5E"/>
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="Border">
                                <EasingColorKeyFrame KeyTime="0" Value="#FF818181"/>
                            </ColorAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Offset)" Storyboard.TargetName="Border">
                                <EasingDoubleKeyFrame KeyTime="0" Value="0.9"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="MouseOver">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="Border">
                                <EasingColorKeyFrame KeyTime="0" Value="#FF383838"/>
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="Border">
                                <EasingColorKeyFrame KeyTime="0" Value="#FF5A5A5A"/>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Pressed">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="Border">
                                <EasingColorKeyFrame KeyTime="0" Value="#FF5A5A5A"/>
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="Border">
                                <EasingColorKeyFrame KeyTime="0" Value="#FF383838"/>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Disabled">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="Border">
                                <EasingColorKeyFrame KeyTime="0" Value="#FFBCBCBC"/>
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="Border">
                                <EasingColorKeyFrame KeyTime="0" Value="#FFABABAB"/>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <ContentPresenter 
                Margin="2"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                RecognizesAccessKey="True"/>
        </Border>
    </ControlTemplate>

1 个答案:

答案 0 :(得分:1)

它是Visual Studio的bug,我可以在2010版本上确认这一点。在这种情况下,请尝试设置GradientStop的名称:

<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop x:Name="MyStop1"  <---- Here
                  Color="White"
                  Offset="0" />

    <GradientStop x:Name="MyStop2"  <---- Here
                  Color="White"
                  Offset="0.9" />
</LinearGradientBrush>

并像这样使用:

<ControlTemplate x:Key="GrayButtonTemplate" TargetType="{x:Type ButtonBase}">
    <Border x:Name="Border"  
            CornerRadius="0" 
            BorderThickness="1">

        <Border.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop x:Name="MyStop1" Color="White" Offset="0"/>
                <GradientStop x:Name="MyStop2" Color="White" Offset="0.9"/>
            </LinearGradientBrush>
        </Border.Background>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal">
                    <Storyboard>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Color" Storyboard.TargetName="MyStop2">
                            <EasingColorKeyFrame KeyTime="0" Value="#FF5E5E5E"/>
                        </ColorAnimationUsingKeyFrames>

                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Color" Storyboard.TargetName="MyStop2">
                            <EasingColorKeyFrame KeyTime="0" Value="#FF818181"/>
                        </ColorAnimationUsingKeyFrames>

                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Offset" Storyboard.TargetName="MyStop1">
                            <EasingDoubleKeyFrame KeyTime="0" Value="0.9"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

    ...