我正在尝试为Rectangle的鼠标悬停设置动画,以便矩形下的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 :(得分:0)
我还发现在找到属性时不需要使用括号:
<ColorAnimation Storyboard.TargetProperty="Fill.Drawing.Brush.GradientStops[0].Color" To="#486A71" Duration="0:0:0.5"></ColorAnimation>
我从这个答案得到了提示:Trouble animating RadialGradientBrush in WPF