I'm working on a WPF application with huge performance issues. When a user is going between screens, there should be a quick animation of the current screen fading out and zooming out while the next screen is fading in and sliding in from left. This is clutty as hell.
Now, I came across EntranceThemeTransitionBehavior (http://msdn.microsoft.com/EN-US/library/windows/apps/windows.ui.xaml.media.animation.entrancethemetransition.aspx) but there are 2 things about it I don't get:
- Should this thing work much faster?
- Can it be used for non windows store apps? (just plain old desktop application)
Any best practice / suggestions to create smooth fade + transitions in WPF?
Today I'm doing it with a simple storyboard and opacity animation. Here's an example:
When I run this on 2 screens in parallel, the fades are really slow.
<Grid x:Name="SlideShow" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.Resources>
<Storyboard x:Key="Slide" RepeatBehavior="Forever" Timeline.DesiredFrameRate="30" >
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:7"
Storyboard.TargetName="Ad2"
Storyboard.TargetProperty="Opacity">
<SplineDoubleKeyFrame KeyTime="0:0:0.25" Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:14.75"
Storyboard.TargetName="Ad3"
Storyboard.TargetProperty="Opacity">
<SplineDoubleKeyFrame KeyTime="0:0:0.25" Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:24.25"
Storyboard.TargetName="Ad4"
Storyboard.TargetProperty="Opacity">
<SplineDoubleKeyFrame KeyTime="0:0:0.25" Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:32.75"
Storyboard.TargetName="Ad2"
Storyboard.TargetProperty="Opacity">
<SplineDoubleKeyFrame KeyTime="0:0:0.25" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:32.75"
Storyboard.TargetName="Ad3"
Storyboard.TargetProperty="Opacity">
<SplineDoubleKeyFrame KeyTime="0:0:0.25" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:32.75"
Storyboard.TargetName="Ad4"
Storyboard.TargetProperty="Opacity">
<SplineDoubleKeyFrame KeyTime="0:0:0.25" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
<Grid.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Slide}" />
</EventTrigger>
</Grid.Triggers>
<Image Source="/MyApp;component/Resources/Images/SecondScreen/1.png" Name="Ad1" Opacity="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Image Source="/MyApp;component/Resources/Images/SecondScreen/2.png" Name="Ad2" Opacity="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Image Source="/MyApp;component/Resources/Images/SecondScreen/3.png" Name="Ad3" Opacity="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<Image Source="/MyApp;component/Resources/Images/SecondScreen/4.png" Name="Ad4" Opacity="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>