C#中的用户控件动画
本文关键字:控件 动画 用户 | 更新日期: 2023-09-27 18:15:17
正确。我需要画布下C#中WPF用户控件动画的任何愚蠢的示例。我试过故事下面的所有组合。开始(????(;但它总是会出错。有线索吗?
Storyboard story = new Storyboard();
DoubleAnimation dbWidth = new DoubleAnimation();
dbWidth.From = 0;
dbWidth.To = 200;
dbWidth.Duration = new Duration(TimeSpan.FromSeconds(.25));
DoubleAnimation dbHeight = new DoubleAnimation();
dbHeight.From = 0;
dbHeight.To = 200;
dbHeight.Duration = dbWidth.Duration;
story.Children.Add(dbWidth);
Storyboard.SetTargetName(dbWidth, PluginUControl.Name);
Storyboard.SetTargetProperty(dbWidth, new PropertyPath(UserControl.WidthProperty));
story.Children.Add(dbHeight);
Storyboard.SetTargetName(dbHeight, PluginUControl.Name);
Storyboard.SetTargetProperty(dbHeight, new PropertyPath(UserControl.HeightProperty));
story.Begin(??????);
更新:
我也试着这样做
story.Begin((MainWindow)App.Current.Windows[0]);
我猜是同一个故事。开始(这个(;但没有成功。。。
德米特里·博伊科:
我找到了解决方案!
它需要取代
Storyboard.SetTargetName(dbWidth, PluginUControl.Name);
带有
Storyboard.SetTarget(dbWidth, PluginUControl);