i write the following Code:
public void name(object sender, RoutedEventArgs e)
{
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 1.0;
myDoubleAnimation.To = 0.0;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.2));
sb1 = new Storyboard();
sb1.Children.Add(myDoubleAnimation);
Storyboard.SetTargetName(myDoubleAnimation, one.Name);
Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Grid.OpacityProperty));
sb1.Begin(this);
if (one.Opacity == 0)
{
Container_one.Children.Remove(one);
}
}
but it doesn't wwork correct. The Animation works fine, but the Remove is wrong. How can i combine a Storyboard-End with the call to a methode?
Thnaks a lot.
As the execution of the Storyboard is asynchronous you need to add a "Storyboard Completed" event handler:
story.Completed += new EventHandler(Story_Completed);
then put your Remove code in that:
private void Story_Completed(object sender, EventArgs e)
{
if (one.Opacity == 0)
{
Container_one.Children.Remove(one);
}
}
This will get executed when the Storyboard completes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With