2014-03-26 74 views
1

我有一個動畫在邊境「[未知]」屬性不指向的DependencyObject路徑

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

向我們展示您對邊境的TargetName的XAML。我的猜測是你沒有內部的面板,如果你這樣做,沒有> 1漸變停止? – Kcvin

+0

@NETscape。動畫的使用是在按鈕的控制模板中,我將它添加到了問題中。 –

回答

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> 

    ... 
+0

它給出了以下錯誤:''顏色'名稱不能在'System.Windows.Controls.Border''的名稱範圍中找到。 –

+0

@Hodaya Shalom:'TargetName'應該是您的GradientStop的名稱(在我的情況下是'MyStop2'),而不是'Border'的名稱。 –