2013-02-14 64 views
0

我試圖爲矩形的鼠標懸停設置動畫,以便矩形下的GeometryDrawing的漸變更改顏色。動畫刷幾何繪圖

然而,當我這樣做,我得到以下錯誤:

Cannot resolve all property references in the property path 'Drawing.(0).(1)[0].(2)'. Verify that applicable objects support the properties. 

,我正在使用的代碼如下:

<Canvas> 
    <Rectangle Width="{Binding ElementName=ParentControl, Path=Width}" Height="{Binding ElementName=ParentControl, Path=Height}"> 
     <Rectangle.Resources> 
     </Rectangle.Resources> 
     <Rectangle.Style> 
      <Style TargetType="Rectangle"> 
       <Style.Triggers> 
        <EventTrigger RoutedEvent="MouseEnter"> 
         <BeginStoryboard> 
          <Storyboard> 
           <ColorAnimation Storyboard.TargetProperty="Drawing.(GeometryDrawing.Brush).(RadialGradientBrush.GradientStops)[0].(GradientStop.Color)" To="#486A71" Duration="0:0:0.5"></ColorAnimation> 
          </Storyboard> 
         </BeginStoryboard> 
        </EventTrigger> 
        <EventTrigger RoutedEvent="MouseLeave"> 
         <BeginStoryboard> 
          <Storyboard> 
           <ColorAnimation Storyboard.TargetProperty="Drawing.(GeometryDrawing.Brush).(RadialGradientBrush.GradientStops)[0].(GradientStop.Color)" To="#485A71" Duration="0:0:0.5" FillBehavior="Stop"></ColorAnimation> 
          </Storyboard> 
         </BeginStoryboard> 
        </EventTrigger> 
       </Style.Triggers> 
      </Style> 
     </Rectangle.Style> 
     <Rectangle.Fill> 
      <DrawingBrush> 
       <DrawingBrush.Drawing> 
        <GeometryDrawing> 
         <GeometryDrawing.Geometry> 
          <GeometryGroup> 
           <PathGeometry> 
            <PathFigure StartPoint="2,0"> 
             <PathFigure.Segments> 
              <LineSegment Point="200,0"></LineSegment> 
              <LineSegment Point="200,7"></LineSegment> 
              <LineSegment Point="185,20"></LineSegment> 
              <LineSegment Point="200,33"></LineSegment> 
              <LineSegment Point="200,40"></LineSegment> 
              <LineSegment Point="2,40"></LineSegment> 
             </PathFigure.Segments> 
            </PathFigure> 
           </PathGeometry> 
          </GeometryGroup> 
         </GeometryDrawing.Geometry> 
         <GeometryDrawing.Brush> 
          <RadialGradientBrush GradientOrigin="0, 0.5" Center="0, 0.5" RadiusX="0.90" RadiusY="0.6"> 
           <RadialGradientBrush.GradientStops> 
            <GradientStop Color="#485A71" Offset="0" x:Name="GradientStop0"></GradientStop> 
            <GradientStop Color="#687F9F" Offset="1" x:Name="GradientStop1"></GradientStop> 
           </RadialGradientBrush.GradientStops> 
          </RadialGradientBrush> 
         </GeometryDrawing.Brush> 
         <GeometryDrawing.Pen> 
          <Pen Thickness="2" Brush="#374C6A" /> 
         </GeometryDrawing.Pen> 
        </GeometryDrawing> 
       </DrawingBrush.Drawing> 
      </DrawingBrush> 
     </Rectangle.Fill> 
    </Rectangle> 
</Canvas> 

我明白,我需要理清Storyboard.TargetProperty屬性的值,但是我仍然在學習WPF,所以我不知道如何解決這個問題!

回答

0

好吧,我感到一個傻瓜!看起來我在引用漸變時錯過了一個屬性!

我也發現了,找到物業時,你不需要使用括號:

<ColorAnimation Storyboard.TargetProperty="Fill.Drawing.Brush.GradientStops[0].Color" To="#486A71" Duration="0:0:0.5"></ColorAnimation> 

我得到了這個答案的提示:Trouble animating RadialGradientBrush in WPF