I want a WPF window to fade in when in opens. I set the following trigger for the window load:
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard Name="FormFade">
<DoubleAnimation Name="FormFadeAnimation"
Storyboard.TargetName="Window"
Storyboard.TargetProperty="(Window.Opacity)"
From="0.0" To="1.0" Duration="0:0:5"
AutoReverse="False" RepeatBehavior="1x"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
The issue is that when the window first loads, it shows all white for the content then disappears and then the window contents fades in as expected. How can I get rid of the flash of white that happens at the beginning? I have even set the background of the window to black but it still flashes white.
I believe the problem is caused by processing in your Window.Loaded handler. The Animation will not run until your Window.Loaded handler finishes executing. I was able to recreate your problem by doing this:
The Screen will be White for 1000ms because the animation will not run until the Sleep ends. If you take away the Thread.Sleep() call, the result is what you would expect. My guess is you are doing quite a bit of work in your Loaded handler and the animation is being delayed.
By the way here is the MainWindow.xaml, pretty much the same to what you have: