Click here to Skip to main content
Click here to Skip to main content

Silverlight Page Flip Navigation

By , , 21 Jul 2009
 

Introduction

This article describes how to navigate between pages with flip animation in Silverlight.

Using the Code

The flip animation can be done with the help of PlaneProjection from the namespace System.Windows.Media. You must use the below code snippet in all the XAML pages that needs the flip animation:

<Grid.Projection>
   <PlaneProjection x:Name="Projection"/>
</Grid.Projection>

And in the code base, add a double animation storyboard to flip the page: 

DoubleAnimation daY1 = new DoubleAnimation { From = 0.00, To = 90.00 };
Storyboard.SetTargetName(daY1, "Projection");
Storyboard.SetTargetProperty(daY1, new PropertyPath("RotationX"));
stb1.Children.Add(daY1);
this.Resources.Add("EndOfPage", stb1);
Storyboard stb = new Storyboard();
stb.Duration = new Duration(TimeSpan.FromSeconds(1));
stb.SpeedRatio = 3;
DoubleAnimation daY = new DoubleAnimation { From = -90.00, To = 0.00 };
Storyboard.SetTargetName(daY, "Projection");
Storyboard.SetTargetProperty(daY, new PropertyPath("RotationX"));
stb.Children.Add(daY);
this.Resources.Add("StartOfPage", stb);

And use this method to navigate from page to page:

public void SwitchToPage(UserControl p)
{
    NextPage = p;
    if (CurrentPage != p)
    {
        Storyboard currStb = CurrentPage.Resources["EndOfPage"] as Storyboard;
        currStb.Completed += new EventHandler(currStb_Completed);
        currStb.Begin();
    }
}

History

  • 21st July, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License

About the Authors

Venkatesan Jagadisan
Software Developer iSOFT
India India
Member
Working as a Software Engineer in iSOFT at Chennai, India.

Balaji Ganesaan
Software Developer (Senior) iSOFT
India India
Member
Working as a Senior Software Engineer in iSOFT at Chennai, India.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
BugI need Help with public void SwitchToPage(UserControl p) in vb.netmemberder22018 Aug '11 - 20:11 
GeneralMy vote of 2memberMichael Eber31 Dec '09 - 7:51 
GeneralMy vote of 1memberwaletzky15 Sep '09 - 16:20 
QuestionExcellent Article,but one question!memberGomathiR25 Aug '09 - 1:06 
AnswerRe: Excellent Article,but one question!memberkamrajj25 Aug '09 - 3:18 
GeneralRe: Excellent Article,but one question!memberGomathiR25 Aug '09 - 20:39 
QuestionGood work but i dont know what am I missingmemberkamrajj24 Aug '09 - 0:00 
Generaldocumentation pleasememberTJDOAD12 Aug '09 - 11:04 
Generalcool codememberforgetuu11 Aug '09 - 17:54 
GeneralMy vote of 1memberpositronvx27 Jul '09 - 22:15 
GeneralMy vote of 1memberMichael E. Jones27 Jul '09 - 21:33 
GeneralRe: My vote of 1memberjasenschmidt3 Aug '09 - 19:29 
This posting is not really all the valid, if you are going to use the same animation for all the pages. Then you only need to have the MainPage.xaml contain the following:
<UserControl x:Class="SilverlightFlipNavigation.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="auto" Height="auto">
    <Grid x:Name="LayoutRoot" Opacity="1"> 
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.167*"/>
            <ColumnDefinition Width="0.681*"/>
        </Grid.ColumnDefinitions>
        <Border BorderBrush="#FF2DA2AC" BorderThickness="3,3,3,3" VerticalAlignment="Stretch" CornerRadius="5,5,5,5" Background="{x:Null}" Margin="0,0,0,0" Opacity="1"/>
        <StackPanel Grid.Column="0" Margin="10,10,10,10" >
            <Button Content="Page 1" Margin="0,10,0,10" Click="Button1_Click"></Button>
            <Button Content="Page 2" Margin="0,10,0,10" Click="Button2_Click"></Button>
            <Button Content="Page 3" Margin="0,10,0,10" Click="Button3_Click"></Button>
            <Button Content="Page 4" Margin="0,10,0,10" Click="Button4_Click"></Button>
        </StackPanel>
 
        <Border Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" BorderBrush="#FF2DA2AC" BorderThickness="3,3,3,3" Background="{x:Null}" CornerRadius="5,5,5,5">
            <Grid x:Name="PageContainer" RenderTransformOrigin="0.212,0.857" Margin="3,3,3,3">
                <Grid.Projection>
                    <PlaneProjection x:Name="PageContainerProjection"/>
                </Grid.Projection>
            </Grid>
        </Border>
    </Grid>
</UserControl>
 
The other pages would have to have the following:
<UserControl x:Class="SilverlightFlipNavigation.Page3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="Auto" Height="Auto">
	<Grid x:Name="LayoutRoot" Background="Gray">
		<TextBlock Text="Page 3" FontSize="20"></TextBlock>
	</Grid>
</UserControl>
 
This removes the need to have the PlaneProjection in each of the pages and therefore you can remove the code from each of the the Page{number}.xaml.cs files
 
The only thing that you would need to change in the current code is the way the resources are accessed before call begin on the animation and that would be to use the MainPage's resources instead of calling CurrentPage and NextPage
 
example Storyboard stb = NextPage.Resources["StartOfPage"] as Storyboard; becomes Storyboard stb = this.Resources["StartOfPage"] as Storyboard;
GeneralMy vote of 2memberlneir27 Jul '09 - 15:48 
GeneralCool code, not so cool articlememberblackjack215021 Jul '09 - 20:43 
Generalexcellentmemberarun123@poll21 Jul '09 - 20:23 
GeneralMy vote of 1memberMW_Justin21 Jul '09 - 6:15 
GeneralRe: My vote of 1memberVenkatesan Jagadisan21 Jul '09 - 7:18 
GeneralMy vote of 2memberemilio_grv21 Jul '09 - 2:25 
GeneralRe: My vote of 2memberBalaji Ganesaan21 Jul '09 - 19:02 
GeneralRe: My vote of 2memberemilio_grv1 Jan '10 - 4:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 21 Jul 2009
Article Copyright 2009 by Venkatesan Jagadisan, Balaji Ganesaan
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid