【问题标题】:'[Unknown]' property does not point to a DependencyObject in path“[未知]”属性未指向路径中的 DependencyObject
【发布时间】:2014-05-04 13:33:00
【问题描述】:

我在边框上有一个动画

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

【问题讨论】:

  • 向我们展示您为 Border TargetName 提供的 XAML。我的猜测是你里面没有面板,如果你有,没有> 1个渐变停止?
  • @NETscape。动画的使用在按钮的控制模板中,我在问题中添加了。

标签: wpf animation binding storyboard


【解决方案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>

    ...

【讨论】:

  • 它给出了以下错误:'Color' name cannot be found in the name scope of 'System.Windows.Controls.Border'.
  • @Hodaya Shalom:TargetName 应该是 GradientStop 的名称(在我的例子中是 MyStop2),而不是 Border 的名称。
猜你喜欢
  • 2012-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-26
  • 1970-01-01
  • 2016-05-21
相关资源
最近更新 更多