如何在wpf c#代码中使用故事板旋转网格

如何在wpf c#代码中使用故事板旋转网格,c#,wpf,xaml,C#,Wpf,Xaml,我想用wpf中的c#代码中的故事板旋转简单网格 我的xaml代码是 <Window x:Class="rotate_test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.mic

我想用wpf中的c#代码中的故事板旋转简单网格 我的xaml代码是

<Window x:Class="rotate_test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:rotate_test"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid Name="my_grid">
            <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="150,170,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
        </Grid>
    </Grid>
</Window>
但它不起作用 我有什么问题? 如何设置动画的加速度?
thnx

在设置网格动画之前,必须初始化网格的
渲染转换

<Grid Name="my_grid">
    <Grid.RenderTransform>
        <RotateTransform />
    </Grid.RenderTransform>
</Grid>
并在代码隐藏中设置动画,如

transform.BeginAnimation(RotateTransform.AngleProperty, rotateAnimation);


除此之外,DoubleAnimation还有几个控制加速和减速的属性,如
加速比
减速比
测量功能

您知道如何设置加速吗?请查看我在回答中提到的属性的在线文档。您可能需要设置EasingFunction。请看这里:
<RotateTransform x:Name="transform" />
transform.BeginAnimation(RotateTransform.AngleProperty, rotateAnimation);