Click here to Skip to main content
Email Password   helpLost your password?

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?

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

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralViewStack Component for Silverlight 2
QuentinB
6:33 22 Oct '08  
The ViewStack component is excellent, and very useful.

I would like to be able to put ViewStack on a View of another ViewStack but can not seem to get it to work.

Is it possible to do this?
AnswerRe: ViewStack Component for Silverlight 2 [modified]
Anil Kumar T R
22:05 22 Oct '08  
Yes offcourse, this issue has been fixed in the extended version. Plese try the source code available at http://www.codeproject.com/KB/silverlight/silverlightviewstack-ex.aspx and let me know.

Anil Kumar T.R

Technical Manager
Digital Mesh Softech India (P) Ltd.
www.digitalmesh.co.in
modified on Tuesday, October 28, 2008 3:31 AM

GeneralRe: ViewStack Component for Silverlight 2
QuentinB
18:38 23 Oct '08  
I was not able to get this working with the new code. Perhaps you could add this to you next demo project.

The transitions are excellent. I have not yet tried the caching.

Regards,

Quentin.
GeneralRe: ViewStack Component for Silverlight 2
Anil Kumar T R
19:22 23 Oct '08  
I would like to have the exact error and the source code you have tried, so that I could resolve this issue.

Anil Kumar T.R

Technical Manager
Digital Mesh Softech India (P) Ltd.
www.digitalmesh.co.in


Last Updated 18 Oct 2008 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010