Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all!

Im developing wpf application where mainwindow presents one view (view = UserControl) at the time. Moving between views launches storyboard where old view is replaced new one with slide effect. Views dimension are 1024 x 768 and transiton takes about 0,5 seconds.

So far I have been developing my application with "dummy" views which is basically usercontrol with image background and thats it. Transitions works smoothly.

Recently I have been developing my views, adding real ui components like buttons, comboboxes and custom usercontrols on it and codebehind code and now I faced real problem. My transition are laggy and not smooth at all!

So is there any tips to increase my transition performance? maybe disabling / changing my usercontrol state while in transition?

UPDATE:

I'll add some code to show basic idea to easilly reproduce example application. Just create new wpf application " TransitionTest"

MainWindow.xaml

<Window x:Class="TransitionTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="768" Width="1024">
    
    <Window.Resources>
        <Storyboard x:Key="SlideIn" >
            <ThicknessAnimation Duration="0:0:0.5" Storyboard.TargetProperty="Margin" From="1024,0,0,0" To="0" DecelerationRatio="1" />
        </Storyboard>
    </Window.Resources>
    
    <Grid x:Name="mainView">      
        <ContentPresenter x:Name="contentPresenter" Grid.Row="0"> </ContentPresenter>        
        <Button Height="30" VerticalAlignment="Bottom" Content="Load UserControl" Click="LoadUserControl_Click"></Button>
    </Grid>
</Window>


and event handler for button in MainWindow.cs

private void LoadUserControl_Click(object sender, RoutedEventArgs e)
      {
          //in practice we have multiple usercontrols filled with custom ui components / usercontrols and codebehind code
          //in this example create usercontrol on the fly..
          UserControl View = new UserControl();
          View.Background = Brushes.Green;
          contentPresenter.Content = View;

          Storyboard showNewPage = Resources["SlideIn"] as Storyboard;
          showNewPage.Begin(contentPresenter);
      }


Hope you got idea :)

Appreciate your thoughts!

Cheers!
Posted
Updated 7-Dec-11 1:48am
v2
Comments
Sergey Alexandrovich Kryukov 7-Dec-11 5:50am    
This can be a pretty difficult problem (or not, let's see). My 5 for the question. First, do you use WPF animation or some self-made approach, like with a timer? If you did not try animation, I suggest you do (but I think you did as you mention "storyboard"). With timer, it's easy to do a number of mistakes killing smoothness. What happens if you do it slower? Will it restore smoothness, even at the cost of speed?
--SA
paleGegg0 7-Dec-11 7:51am    
Hello there! Example does not provide real loadable UserControls but gives idea about transitions.
Sergey Alexandrovich Kryukov 7-Dec-11 10:18am    
OK, I see, thank you. So, how about my question about longer animation time? Unfortunately, I would need to try it by myself but I don't know when could I do it...
--SA
paleGegg0 8-Dec-11 0:11am    
Unfortunately animation is specced to be less than 0.5. I have been testing our usercontrols and been noticing that components with dropshadow effect, custom controls with opacity seems to be heavier to handle in storyboard. Also one of the usercontrol had database query in onloaded event which gave hiccup to slide animation so basically it seems that usecontrols are too heavy. I'll keep thread alive for while if someone has tips to speed up performance. Thanks for your time though :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900