.net - 如何克隆动画画笔?

标签 .net wpf animation clone brush

我有一个动画Brush对象,我想要 Clone这把刷子。

ColorAnimation ani = new ColorAnimation(Colors.White, TimeSpan.FromSeconds(1))
{ RepeatBehavior = RepeatBehavior.Forever, AutoReverse = true };

SolidColorBrush brush1 = new SolidColorBrush(Colors.Black);
brush1.BeginAnimation(SolidColorBrush.ColorProperty, ani);

SolidColorBrush brush2 = brush1.Clone();

// brush2 is not an animated Brush

if (!brush2.HasAnimatedProperties)
    MessageBox.Show("I don't want this!");

正如 MSDN Library 所说(Brush.Clone 方法):

Creates a modifiable clone of this Brush, making deep copies of this object's values. When copying dependency properties, this method copies resource references and data bindings (but they might no longer resolve) but not animations or their current values.

那么,克隆动画画笔的最佳方法是什么? 谢谢。

最佳答案

您需要在克隆上重新创建动画。没有其他办法。

关于.net - 如何克隆动画画笔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10566487/

相关文章:

c# - virtual、abstract、override 关键字的排序

c# - 第 1 行 'date' 列的日期时间值不正确

c# - wpf 中的 mvvm - 操作由哪个控件触发

java - 生成随机动画时遇到问题

javascript - 当组件在 View 中时在 react-spring 中启动动画

c# webrequest 挂起

c# - 将 AvalonEdit 绑定(bind)到 XML

.net - 代码和 XAML 中图像 URI 行为的区别

java - OnDraw() 动画仅在项目移动时运行

c# - Func<> 和原始代码