Click here to Skip to main content
15,893,487 members
Articles / Programming Languages / C#

Silverlight Tutorial: Creating an Animated Navigation Bar using Storyboards

Rate me:
Please Sign up or sign in to vote.
4.07/5 (8 votes)
4 Aug 2008CPOL6 min read 70.3K   772   42  
First article in a series. This article focuses on the use of storyboards for creating animation effects.
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 TutorialNavbarXap
{
    public partial class Page : UserControl
    {
        Nav1Page m_nav1Page = new Nav1Page();
        Nav2Page m_nav2Page = new Nav2Page();
        Nav3Page m_nav3Page = new Nav3Page();

        public Page()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(PageLoaded);

        }

        void PageLoaded(object sender, RoutedEventArgs e)
        {
            // Remove all content add then add the Nav1Page
            RemoveAll();
            ContentCanvas.Children.Add(m_nav1Page);

            // Highlight Nav1
            HighlightNone();
            Nav1Highlight.Opacity = 100.0;

        }

        void RemoveAll()
        {
            ContentCanvas.Children.Remove(m_nav1Page);
            ContentCanvas.Children.Remove(m_nav2Page);
            ContentCanvas.Children.Remove(m_nav3Page);
        }

        private void OnNav1Click(object sender, MouseButtonEventArgs e)
        {
            RemoveAll();
            ContentCanvas.Children.Add(m_nav1Page);
        }

        private void OnNav2Click(object sender, MouseButtonEventArgs e)
        {
            RemoveAll();
            ContentCanvas.Children.Add(m_nav2Page);
        }

        private void OnNav3Click(object sender, MouseButtonEventArgs e)
        {
            RemoveAll();
            ContentCanvas.Children.Add(m_nav3Page);
        }

        private void HighlightNone()
        {
            Nav1Highlight.Opacity = 0.0;
            Nav2Highlight.Opacity = 0.0;
            Nav3Highlight.Opacity = 0.0;

        }

        private void OnNav1Enter(object sender, MouseEventArgs e)
        {
            HighlightNone();
            Nav1Highlight.Opacity = 100.0;
            MoveToNav1.Begin();
        }

        private void OnNav2Enter(object sender, MouseEventArgs e)
        {
            HighlightNone();
            Nav2Highlight.Opacity = 100.0;
            MoveToNav2.Begin();
        }

        private void OnNav3Enter(object sender, MouseEventArgs e)
        {
            HighlightNone();
            Nav3Highlight.Opacity = 100.0;
            MoveToNav3.Begin();
        }

    }
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior) SilverlightWebApps.com
United States United States
Mike Dobbles is a freelance software developer specializing in Silverlight and C#. Mike has over 15 years of software development experience.

Comments and Discussions