WPf路径轮换不起作用

时间:2016-06-30 10:55:06

标签: wpf xaml

我想在从datacontext更改属性时旋转Path。我添加了一个colorchange来查看实际执行的故事板。但没有轮换......

<Grid Grid.Column="0" Grid.Row="0" Background="Green" Margin="0,10,10,10" Width="100" Height="100">
        <Grid.Resources>
            <Style TargetType="Path">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Expanded}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <local:BrushAnimation Duration="0:0:1" To="Red" Storyboard.TargetProperty="Fill"/>
                                    <DoubleAnimation Duration="0:0:1" To="45" Storyboard.TargetProperty="(LayoutTransform).(RotateTransform.Angle)"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Duration="0:0:2" To="90" Storyboard.TargetProperty="(LayoutTransform).(RotateTransform.Angle)"/>
                                    <local:BrushAnimation Duration="0:0:2" To="Yellow" Storyboard.TargetProperty="Fill"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.ExitActions>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Grid.Resources>

        <Path VerticalAlignment="Stretch" Fill="Aqua" Stretch="Uniform" RenderTransformOrigin="0.5, 0.5">
            <Path.Data>
                <StreamGeometry>F1M154.2217,60.96L45.7777,100L154.2217,139.04z</StreamGeometry>
            </Path.Data>
        </Path>
    </Grid>

1 个答案:

答案 0 :(得分:3)

您必须先向RotateTransform第一个

添加Path
<Path VerticalAlignment="Stretch" Fill="Aqua" Stretch="Uniform" RenderTransformOrigin="0.5, 0.5" x:Name="Path">
            <Path.Data>
                <StreamGeometry>F1M154.2217,60.96L45.7777,100L154.2217,139.04z</StreamGeometry>
            </Path.Data>
            <Path.LayoutTransform>
                <RotateTransform Angle="0"></RotateTransform>
            </Path.LayoutTransform>
        </Path>