Click here to Skip to main content
5,788,212 members and growing! (18,817 online)
Email Password   helpLost your password?
Web Development » Silverlight » Controls     Beginner License: The Code Project Open License (CPOL)

ViewStack Component for Silverlight 2 – An Inevitable Control in RIA Space

By Anil Kumar T R

ViewStack component for Silverlight 2 – An inevitable control in RIA space
C# 3.0, C# 2.0, C#.NET, .NET 3.0, .NET 2.0, .NET 3.5, XAML, Silverlight, Design, Architect, Dev

Posted: 17 Oct 2008
Updated: 17 Oct 2008
Views: 3,719
Bookmarked: 11 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 3.03 Rating: 3.89 out of 5
1 vote, 16.7%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 16.7%
4
4 votes, 66.7%
5

Introduction

I find that the ViewStack component in Flex is an elegant navigator for switching views in defined content panes. Unfortunately I couldn't find any such navigator within Silverlight 2 SDK. So I thought of developing a simple ViewStack component for my project DShop, a Silverlight 2 technology demonstrator. I will be enhancing this control with more features and would like to have your valuable comments.

What is ViewStack?

  • A ViewStack is a navigator container that contains other child containers stacked on top of each other.
  • Only one child container can be visible or active at a time.
  • You can create your own logic to manage active views.
  • The SelectedIViewName property contains the logical name of the active view.
  • Simply change the SelectedViewName property from model to switch the view (ModelLocator.Instance.SelectedViewName = "Home").

Code

Page.xaml.cs

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()
        {
            InitializeComponent();
            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";
        }
    }
}

Page.xaml

<UserControl x:Class="SilverlightApplication1.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:SilverlightApplication1.Control" >
    <Grid x:Name="LayoutRoot" Background="Wheat"  >
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="20"/>
            <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="Home" Content="Home" Grid.Row="0" 
					Grid.Column="0" Click="Home_Click"/>
        <Button x:Name="AboutUS" Content="AboutUS" Grid.Row="0" 
					Grid.Column="2" Click="AboutUS_Click"/>
        
         <Grid Grid.Row="2" Grid.ColumnSpan="4" Grid.Column="0">
                <local:ViewStack x:Name="myViewStack"  
		    SelectedViewName="{Binding Path=SelectedViewName,Mode=TwoWay}" >
                    <local:ViewStack.Views>
                        <local:ViewInfo ViewName="Home" 
			ViewTypeName="SilverlightApplication1.HomeView"/>
                        <local:ViewInfo ViewName="AboutUS" 
			ViewTypeName="SilverlightApplication1.AboutUSView"/>
                    </local:ViewStack.Views>
                </local:ViewStack>
         </Grid>
    </Grid>
</UserControl>

viewstack.GIF

History

  • 18th October, 2008: Initial post

License

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


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 (www.digitalmesh.co.in)
Occupation: Architect
Company: Digital Mesh Softech India (P) Ltd.
Location: India India

Other popular Silverlight articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
GeneralViewStack Component for Silverlight 2memberQuentinB6:33 22 Oct '08  
AnswerRe: ViewStack Component for Silverlight 2 [modified]memberAnil Kumar T R22:05 22 Oct '08  
GeneralRe: ViewStack Component for Silverlight 2memberQuentinB18:38 23 Oct '08  
GeneralRe: ViewStack Component for Silverlight 2memberAnil Kumar T R19:22 23 Oct '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Oct 2008
Editor: Deeksha Shenoy
Copyright 2008 by Anil Kumar T R
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project