Window Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 19 November 2008

Silverlight 2 : Master Pages implementation in Silverlight 2

Posted on 10:10 by Unknown

The title of the post may be sound funny, and it was fun since many arguments did happen while whole process of this implementation.

There are several post made by several expertise and enthus on the same, Basically a big question is do we need this?? since all Silverlight application however powerful they are, they are still run under umbrella of ASP.NET. I agree on this !

But there might be some business scenarios, if not now then might be in future, so keeping this vision in mind, here I am showing you a very easy way to implement Master Page concept in Silverlight, It is not difficult code and neither we need to touch App.xaml file..here I go :

SLMasters1

This is what I want to build, You can see header part "Explore .NET with Vikram Pendse" followed by buttons [Third Party Silverlight Control may provide you good Menu bar too] and footer as "Microsoft .NET for everyone !!".

Now once I click on Home or RSS or any other button, Idea is to keep header and footer as it is and load other page contents in middle blank portion as content if we assume this page as Master page. so the required XAML code is,

XAML Code :

<Grid x:Name="LayoutRoot" Background="AliceBlue">
        <Button x:Name="btnBlog" Height="22" Width="67" Content="Blog" Margin="161.5,36,171.5,0" VerticalAlignment="Top" d:LayoutOverrides="Width, Height" Click="btnBlog_Click"/>
        <Button x:Name="btnRSS" Height="22" Width="67" Content="RSS" HorizontalAlignment="Left" Margin="94,36,0,0" VerticalAlignment="Top" d:LayoutOverrides="Width, Height" Click="btnRSS_Click"/>
        <Button x:Name="btnHome" Height="22" Width="67" Content="Home" HorizontalAlignment="Left" Margin="27,36,0,0" VerticalAlignment="Top" d:LayoutOverrides="Width, Height" Click="btnHome_Click"/>
        <Button x:Name="btnDownload" Height="22" Width="67" Content="Download" Margin="0,36,104,0" VerticalAlignment="Top" HorizontalAlignment="Right" d:LayoutOverrides="Width, Height" Click="btnDownload_Click"/>
        <Button x:Name="btnAbtus" Height="22" Width="67" Content="About Us" Margin="0,36,37,0" VerticalAlignment="Top" HorizontalAlignment="Right" d:LayoutOverrides="Width, Height" Click="btnAbtus_Click"/>
        <TextBlock Height="23" Margin="94,8,116,0" VerticalAlignment="Top" Text="Explore .NET with Vikram Pendse" TextWrapping="Wrap" Foreground="#FF000000"/>
        <StackPanel x:Name="stk" Width="400" Margin="0,66,0,30"/>

        <TextBlock Height="23" Margin="106,0,104,3" VerticalAlignment="Bottom" Text="Microsoft .NET for everyone!!" TextWrapping="Wrap" Foreground="#FF000000"/>
    </Grid>

Here you can see that I am using "stk" as my contentplace holder stack where I will load the other pages on each corresponding button clicks, rest of the code is just routine design.

C# Code :

namespace SL_MasterPages
{
    public partial class Page : UserControl
    {
        int var = 0;

        public Page()
        {
            InitializeComponent();
        }

        private void NavigateRequest(int w)
        {
            if(w>0)
            {
                switch(w)
                {
                    case 1:  stk.Children.Add(new RSS());
                             break;
                    case 2:  stk.Children.Add(new Home());
                             break;
                    default: this.Content = new Page();
                             break;
                }
            }
        }

     private void btnRSS_Click(object sender, RoutedEventArgs e)
        {
            stk.Children.Clear();
            var = 1;
            NavigateRequest(var);
        }

        private void btnHome_Click(object sender, RoutedEventArgs e)
        {
            stk.Children.Clear();
            var = 2;
            NavigateRequest(var);
        }
   }
}

Here I have implemented for first two buttons, I am setting and resetting flag values for each button with a global variable as "var", and I am clearing stack in each click so as to keep contents dynamic in nature.

I have written a "NavigateRequest" sub proc which takes integer value just for switching between two pages. So this is very simple way to switch between the pages from one to anothet and result will be like..

SLMasters2

SLMaster3

Now you can see messages like "You are on Home Page", "You are on RSS Page", these you will get once you click on corresponding button on Main Header and you also have observed now that header and footer are constant in all case like Master Pages in ASP.NET

Hope this will encourage you to go ahead and explore it more and apply the same in all possible business scenarios which need this kind of implementation.

Feedback and suggestions for this are most welcome, I will be more than happy to know if there are any more simple and good way to implement such things.

Vikram.

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • First Windows Phone 7 update February 2011 - Small update but Big start
    After tons of rumors and set of predictions on Windows Phone 7 all over Internet, Microsoft came up with first Windows Phone 7 minor update ...
  • The little Story of “I Unlock Joy” event by Microsoft and Pune User Group
      This post is about recent “I Unlock Joy” event happened in Pune which was conducted by Microsoft and Pune User Group. Little History : ...
  • Silverlight On Mobile : Windows Phone 7 Splash Screen and Customization
    After talking about 3D capabilities on Windows Phone 7 using Silverlight in last article , Now I am moving ahead with small but equally impo...
  • Silverlight 5 : Platform Invoke (PInvoke) in Silverlight
      Two days back Microsoft announced availability of Silverlight 5 RC,I encourage you to download bits from here , My friend Pete Brown alr...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 1
    After a long..I am writing blog, I hope and I wish I will resume blogging like I use to in past. Lots of things happened in past few months....
  • MCTS : Microsoft Silverlight 4 Development Exam Guide (70-506) by Packt Publishing
      Hello, After a long time I got chance to come back here.I will soon resume blogging in month of August. Last 4-5 months were horrible due...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 2
    Hope you enjoyed my last article on Speech Capability in Windows Phone 8, Today I am posting another part or you can say little extension t...
  • Silverlight 3 : Insert & Update Data using WCF Service with DataForm and DataGrid
    In my Lap around Silverlight 3 series, I have written a separate article on DataForm in Silverlight 3, This article is a basic extension to ...
  • Mango : Using DeviceStatus in Windows Phone 7.1
    First of all “Thank You” for your wonderful response and comments on my last article on Silverlight Vs HTML5 ,I hope you like the points I ...
  • Silverlight, HTML5 & Windows 8 : Where we are heading to ?
    This is not the post or yet another post on most happening debate of Silverlight and HTML5, This is just a visit to all of them to realize t...

Blog Archive

  • ►  2013 (4)
    • ►  August (1)
    • ►  April (3)
  • ►  2012 (4)
    • ►  July (1)
    • ►  March (2)
    • ►  January (1)
  • ►  2011 (24)
    • ►  December (1)
    • ►  September (4)
    • ►  August (2)
    • ►  July (1)
    • ►  June (4)
    • ►  May (3)
    • ►  April (3)
    • ►  March (1)
    • ►  February (4)
    • ►  January (1)
  • ►  2010 (21)
    • ►  December (1)
    • ►  November (2)
    • ►  October (3)
    • ►  September (2)
    • ►  August (4)
    • ►  July (5)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  January (1)
  • ►  2009 (49)
    • ►  December (1)
    • ►  November (5)
    • ►  October (2)
    • ►  September (1)
    • ►  August (5)
    • ►  July (5)
    • ►  June (1)
    • ►  May (5)
    • ►  April (5)
    • ►  March (9)
    • ►  February (4)
    • ►  January (6)
  • ▼  2008 (43)
    • ►  December (3)
    • ▼  November (9)
      • Terror attacks on Mumbai : India’s 9/11
      • DeepZoom with PhotoZoom and Silverlight.live.com
      • Silverlight 2 : Master Pages implementation in Sil...
      • Ultimate Windows Tweaker is here : Great job by Pu...
      • Windows 7 : Lap around new version of Windows
      • South Asia MVP Open Day '08, Goa ,India
      • Migrate DataSet to List<Type> for Data Binding for...
      • Bill Gates Visit to my city “Pune” and DreamSpark ...
      • Silverlight 2 : Theming from Silverlight 2 Toolkit
    • ►  October (7)
    • ►  September (4)
    • ►  August (2)
    • ►  July (3)
    • ►  June (4)
    • ►  May (3)
    • ►  March (3)
    • ►  February (5)
Powered by Blogger.

About Me

Unknown
View my complete profile