0

我正在尝试为 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,所以我不太知道如何解决这个问题!

4

1 回答 1

0

好吧,我觉得自己很傻!看起来我在引用渐变时错过了一个属性!

我还发现在查找属性时不需要使用括号:

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

我从这个答案中得到了提示:Trouble animating RadialGradientBrush in WPF

于 2013-02-14T10:25:26.643 回答