c# - 从代码中为 WPF 中的 MatrixTransform 设置动画

标签 c# wpf animation matrix transform

我有一个 Canvas,我需要为它的 RenderTransform 属性设置动画。开始和结束矩阵是任意的,所以我不能用 XAML 预先编写 Storyboard,所以我试图用代码来做,我找不到任何如何做到这一点的例子,下面是我最好的尝试这不起作用(它编译并运行,但 rendertransform 没有改变)。

关于如何完成这件事有什么建议吗?

MatrixAnimationUsingKeyFrames anim = new MatrixAnimationUsingKeyFrames();
MatrixKeyFrameCollection keyframes = new MatrixKeyFrameCollection();
DiscreteMatrixKeyFrame start = new DiscreteMatrixKeyFrame(fromMatrix, KeyTime.FromPercent(0));
DiscreteMatrixKeyFrame end = new DiscreteMatrixKeyFrame(toMatrix, KeyTime.FromPercent(1));

keyframes.Add(start);
keyframes.Add(end);
anim.KeyFrames = keyframes;

Storyboard.SetTarget(anim, World.RenderTransform);
Storyboard.SetTargetProperty(anim, new PropertyPath("Matrix"));

Storyboard sb = new Storyboard();
sb.Children.Add(anim);
sb.Duration = TimeSpan.FromSeconds(4);
sb.Begin();

最佳答案

我已经实现了支持平滑平移、缩放和旋转动画的 MatrixAnimation 类。它还支持缓动功能!查找 http://pwlodek.blogspot.com/2010/12/matrixanimation-for-wpf.html

关于c# - 从代码中为 WPF 中的 MatrixTransform 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/915212/

相关文章:

c# - RxUI ObservableAsPropertyHelper 不适用于 XAML 绑定(bind)

ios - 如何提高 iOS 汉堡菜单的 CSS 性能?

android - Android SDK 中的 overridePendingTransition 不起作用

c# - 在 Dynamics CRM 中调用 OrganizationService.Associate() 和显式设置实体的外键字段有什么区别?

c# - .NET Web 应用程序中的 native 依赖项未加载

c# - .NET 可集成的稳健、快速的 3D 点云表面重建解决方案

wpf - 剪贴板更改通知?

iphone - 同时隐藏状态栏和导航栏,就像在图片应用程序中一样

c# - “using System;”产生编译错误

c# - 由于 System.Net.Http.Formatting.dll 将 Newtonsoft.Json 6.0 升级到 8.0 时出现问题