Click here to Skip to main content
15,885,546 members
Articles / Web Development / XHTML

Silverlight Page Flip Navigation

,
Rate me:
Please Sign up or sign in to vote.
3.14/5 (20 votes)
21 Jul 2009CC (ASA 2.5) 93.3K   3.1K   34  
It describes page to page navigation with flip animation in Silverlight
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightFlipNavigation
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            Storyboard stb1 = new Storyboard();
            stb1.Duration = new Duration(TimeSpan.FromSeconds(1));
            stb1.SpeedRatio = 3;

            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);

            Page1 oPage1 = new Page1();
            PageContainer.Children.Add(oPage1);
        }

        private UserControl currentPage;

        public UserControl CurrentPage
        {
            get { return this.PageContainer.Children[0] as UserControl; }
            set { currentPage = value; }
        }

        private UserControl nextPage;

        public UserControl NextPage
        {
            get { return nextPage; }
            set { nextPage = value; }
        }

        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();
            //}
        }

        void currStb_Completed(object sender, EventArgs e)
        {
            this.PageContainer.Children.RemoveAt(0);
            this.PageContainer.Children.Add(NextPage);
            Storyboard stb = NextPage.Resources["StartOfPage"] as Storyboard;
            stb.Begin();
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            Page1 oPage1 = new Page1();
            SwitchToPage(oPage1);
        }
        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            Page2 oPage2 = new Page2();
            SwitchToPage(oPage2);
        }
        private void Button3_Click(object sender, RoutedEventArgs e)
        {
            Page3 oPage3 = new Page3();
            SwitchToPage(oPage3);
        }
        private void Button4_Click(object sender, RoutedEventArgs e)
        {
            Page4 oPage4 = new Page4();
            SwitchToPage(oPage4);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer iSOFT
India India
Working as a Software Engineer in iSOFT at Chennai, India.

Written By
Software Developer (Senior) iSOFT
India India
Working as a Senior Software Engineer in iSOFT at Chennai, India.

Comments and Discussions