Thursday, 15 August 2013

How to correctly coordinate Windows load animations and C# events?

How to correctly coordinate Windows load animations and C# events?

My WPF application has a window load animation which I created using
Blend. The actual animation works fine, but if I add logic to my window
load event (using C#) the animation skips to end when the window finally
renders.
My initial plan was to use Threading to solve this, but this too didn't work:
private void MyWindow_Loaded(object sender, RoutedEventArgs e)
{
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 30);
dispatcherTimer.Start();
lstRecipients.Visibility = Visibility.Hidden;
windowAdorner = new TransparentAdorner(BorderGrid);
if (!StaticHelpers.AWSConfigurationExists())
{
this.IsEnabled = false;
GettingStarted gettingStarted = new GettingStarted(this);
gettingStarted.Owner = this;
gettingStarted.ShowDialog();
this.IsEnabled = true;
}
else
{
Task SetAWSLabelsTask = new Task(new Action(() => SetAWSLabels()));
SetAWSLabelsTask.Start();
}
Task bounceHandler = new Task(new Action(() => processBounce()));
bounceHandler.Start();
//processBounce();
Task unSubscribeHandler = new Task(new Action(() =>
handleUnsubscriptions()));
unSubscribeHandler.Start();
}
I'm assuming the system is so busy creating the threads, and the creation
is handled by the UI thread, that the animation has already finished by
the time the Window is rendered.
What I'm missing is a good way to coordinate the animation, so that any
business logic I have in MyWindow_Loaded occurs only after the animation
has finished loading.
Is this possible?
EDIT: I also tried a thread sleep, and this too didn't work.

No comments:

Post a Comment