Usercontrol animation in C#

2019-08-28 20:15发布

问题:

Correct. I need any stupid sample of WPF Usercontrol animation in C# under the Canvas. I tried all combinations under story.Begin(??????); But it gives an error always. Any clue guys?

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(??????);

UPDATES:

Also I tried to do like this

 story.Begin((MainWindow)App.Current.Windows[0]);

I guessed that it is the same story.Begin(this); but no success...

回答1:

Dmitry Boyko:

I found the solution guys!

It needs to replace

Storyboard.SetTargetName(dbWidth, PluginUControl.Name);

with

Storyboard.SetTarget(dbWidth, PluginUControl);