Click here to Skip to main content
13,250,043 members (65,272 online)
Click here to Skip to main content
Add your own
alternative version


6 bookmarked
Posted 20 Oct 2008

A ViewStack Component for Silverlight 2 with Transitions and Cache management

, 20 Oct 2008
Rate this:
Please Sign up or sign in to vote.
An enhanced ViewStack component for Silverlight 2 with transitions and cache management.


This is a continuation to my previous article, ViewStack component for Silverlight 2 – An inevitable control in RIA space. I have added Transitions and Cache management feature to our ViewStack control. Please see DShop. Hopefully, Microsoft will add more navigator controls like this in the next release. I hope this control will be useful for the Silverlight community. Please don't hesitate to provide your valuable comments.


We can now apply the following transitions on pages placed in our ViewStack, I will be adding more effects soon.

  • FadeTransition
  • WipeTransition

I have followed the ideas demonstrated at in their article titled Silverlight 2 Navigating Between XAML Pages, for implementing transitions in our ViewStack. I would like to express my sincere thanks for the post.

Cache Management

Pages inside the ViewStack can be configured to be cached or not by setting the Cache property on the ViewInfo object. When the caching feature is turned on, a page once activated will be kept in the cache, and the visibility of the page will be just toggled by setting the Canvas.SetZIndex property during subsequent activations. A fresh instance of the page/usercontrol will be created and displayed if the caching feature is not enabled. The default behaviour is true (i.e., cache).

Using the Code


<UserControl x:Class="SilverlightApplication1.Page"




    <Grid x:Name="LayoutRoot" Background="Wheat"  >
            <RowDefinition Height="20" />
            <RowDefinition Height="50" />
            <RowDefinition Height="20"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="20"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="20"/>
        <Button x:Name="Home" Content="Home" 

           Grid.Row="1" Grid.Column="1" Click="Home_Click"/>
        <Button x:Name="AboutUS" Content="AboutUS" 

           Grid.Row="1" Grid.Column="3" Click="AboutUS_Click"/>
         <Grid Grid.Row="3" Grid.ColumnSpan="4" Grid.Column="1">
                <local:ViewStack x:Name="myViewStack" 

                   SelectedViewName="{Binding Path=SelectedViewName,Mode=TwoWay}"  >
                    <local:ViewInfo ViewName="Home" 


                          Cache="False" >

                               Direction="TopToBottom" Duration="1"/>
                    <local:ViewInfo ViewName="AboutUS" 



                               Direction="LeftToRight" Duration="1"/>


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;
using SilverlightApplication1.Control;

namespace SilverlightApplication1
    public partial class Page : UserControl
        public Page()
            this.Loaded += new RoutedEventHandler(Page_Loaded);

        void Page_Loaded(object sender, RoutedEventArgs e)
            this.DataContext = ModelLocator.Instance;
            ModelLocator.Instance.SelectedViewName = "Home";

        private void Home_Click(object sender, RoutedEventArgs e)
            ModelLocator.Instance.SelectedViewName = "Home";

        private void AboutUS_Click(object sender, RoutedEventArgs e)
            ModelLocator.Instance.SelectedViewName = "AboutUS";



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


About the Author

Anil Kumar T R
Architect Digital Mesh Softech India (P) Ltd.
India India
Started my career in software development in the year 1996 and still trying to learn and implement new technologies. Currently pursuing my career as Technical Architect @ Digital Mesh Softech India (P) Ltd (

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 21 Oct 2008
Article Copyright 2008 by Anil Kumar T R
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid