C# 如何修复图像旋转的双重动画?
我正在尝试为我创建的事件旋转EventHandler上的图像。事件处理程序工作得非常好。然而图像没有旋转,我不知道我错过了什么 此UserControl不是这样显示的,而是在另一个UserControl的网格中显示的C# 如何修复图像旋转的双重动画?,c#,wpf,xaml,animation,storyboard,C#,Wpf,Xaml,Animation,Storyboard,我正在尝试为我创建的事件旋转EventHandler上的图像。事件处理程序工作得非常好。然而图像没有旋转,我不知道我错过了什么 此UserControl不是这样显示的,而是在另一个UserControl的网格中显示的 <UserControl x:Class="Mabri.Module.P83.View.SchematicSystemView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presenta
<UserControl x:Class="Mabri.Module.P83.View.SchematicSystemView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Mabri.Module.P83.View"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Image x:Name="drehteller" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</UserControl>
在测试用例中,e.步数
等于1,e.速度
等于10.0
我希望图像旋转72度,但由于某些原因,除了处理程序开头的日志消息外,什么也没有发生。首先,为图像的RenderTransform属性指定一个RotateTransform。否则它就无法设置动画
<Image x:Name="drehteller" HorizontalAlignment="Center" VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<RotateTransform/>
</Image.RenderTransform>
</Image>
最后,不要创建中间图像元素。这是多余的
drehteller.Source = new BitmapImage(new Uri("..."));
您是否也知道如何在MVVM中实现这一点?如果是的话,请让我知道具体是什么?动画是视图元素。您可能会将By属性绑定到某个视图模型。是的,绑定属性会非常好,但我还没有弄清楚应该绑定什么,我既不能绑定故事板也不能绑定双动画,而且我必须绑定角度和持续时间,这似乎会导致一些问题
var animation = new DoubleAnimation
{
By = angle,
Duration = TimeSpan.FromSeconds(...)
};
drehteller.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, animation);
drehteller.Source = new BitmapImage(new Uri("..."));