How to use themes In Silverlight 3 Application

No.of Views1005
Bookmarked0 times
Downloads 
Votes0
By  dpatra   On  08 Apr 2010 10:04:12
Tag : Silver Light and XAML , Skin And GUI
Themes are nothing but some predefined styles for each and every control. For example you want a Blue Theme for your Silverlight Application that is for all of your controls inside the application.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Themes are nothing but some predefined styles for each and every control. For example you want a Blue Theme for your Silverlight Application that is for all of your controls inside the application. Of course you can do your own templates for your own controls but in Silverlight 3, themes come by default. It makes your Silverlight Application look good in some few steps.
So in this article we are going to see how to use the Themes.
 

Creating Silverlight Project

Fire up Visual Studio 2008 and create a Silverlight Navigation Application. Name it as ThemesInSL3.

 

Image Loading

Open the Solution in Expression Blend 3.
In the Asset library if you look into it you will find several themes under the category Categories-> Theming.  

Image Loading

Here is the idea about our application. As you know I have created a Silverlight Navigation Application, the reason I have used is to display all the themes in different page. If you implement all the themes in a single page the xap file will become too large and the Silverlight plug in will not be able to display your content. It will throw a java script error.
So I have decided to design a set of controls in home page without themes on, and other pages the respective themes will be applied.
For the requirement of the Application I have designed the application as follows:
  

Image Loading

Now we all some controls into the home page and we will replicate all those controls in all our Theme Pages.

 

Image Loading

As we discussed earlier, I have replicated the above design in all the Theme Pages.Now, how can we use the themes for a particular set of controls?
The themes control takes only one control to be inside it, whether it is a button control or a grid control. So you might have got the idea of putting the Grid inside the Theme. Yes, you are right.
Now select the theme for the page and add into the grid, then remove the content property of the theme and drag the Grid inside it. You can do it in design view and in xaml view as well.


The following xaml will help you following it.
 

<ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">
            <bureauBlack:BureauBlackTheme Margin="0,0,8,0" VerticalAlignment="Top" d:LayoutOverrides="Width">
    		<Grid x:Name="ContentGrid" Height="479" Width="640">
    			<Grid.RowDefinitions>
    				<RowDefinition Height="0.071*"/>
    				<RowDefinition Height="0.19*"/>
    				<RowDefinition Height="0.203*"/>
    				<RowDefinition Height="0.537*"/>
    			</Grid.RowDefinitions>
    			<Grid.ColumnDefinitions>
    				<ColumnDefinition Width="0.18*"/>
    				<ColumnDefinition Width="0.203*"/>
    				<ColumnDefinition Width="0.194*"/>
    				<ColumnDefinition Width="0.202*"/>
    				<ColumnDefinition Width="0.222*"/>
    			</Grid.ColumnDefinitions>
    			<TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" Text="TextBlock" TextWrapping="Wrap"/>
    			<TextBox Margin="15,0,15,10" Width="100" Grid.Column="1" Text="TextBox" TextWrapping="Wrap" d:LayoutOverrides="Height"/>
    			<Button HorizontalAlignment="Center" Margin="0,0,0,12" Width="100" Content="Button" Grid.Column="2" d:LayoutOverrides="Height"/>
    			<CheckBox HorizontalAlignment="Center" Margin="0" VerticalAlignment="Top" Content="CheckBox" Grid.Column="3"/>
    			<RadioButton HorizontalAlignment="Center" Margin="0" VerticalAlignment="Top" Content="RadioButton" Grid.Column="4"/>
    			<ComboBox Height="20" Margin="0" VerticalAlignment="Top" Grid.Row="1">
    				<ComboBoxItem Content="ComboBoxItem"/>
    				<ComboBoxItem Content="ComboBoxItem"/>
    				<ComboBoxItem Content="ComboBoxItem"/>
    			</ComboBox>
    			<Slider Margin="0,0,0,16" VerticalAlignment="Center" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" d:LayoutOverrides="Width, Height, GridBox"/>
    			<controls:Calendar HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="3" Grid.ColumnSpan="4" Grid.Row="1" Grid.RowSpan="2" d:LayoutOverrides="Width, Height"/>
    			<inputToolkit:NumericUpDown HorizontalAlignment="Center" Margin="0,0,0,12" VerticalAlignment="Center" Grid.Column="2" Grid.Row="2"/>
    			<ListBox Margin="0" Grid.ColumnSpan="2" Grid.Row="2">
    				<ListBoxItem Content="ListBoxItem"/>
    				<ListBoxItem Content="ListBoxItem"/>
    				<ListBoxItem Content="ListBoxItem"/>
    				<ListBoxItem Content="ListBoxItem"/>
    				<ListBoxItem Content="ListBoxItem"/>
    			</ListBox>
    			<data:DataGrid Margin="0" Grid.Row="3" Grid.ColumnSpan="2">
    				<data:DataGrid.Columns>
    					<data:DataGridCheckBoxColumn/>
    					<data:DataGridTextColumn/>
    				</data:DataGrid.Columns>
    			</data:DataGrid>
    			<ProgressBar Height="30" Margin="0" VerticalAlignment="Center" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="3" IsIndeterminate="True"/>
    		</Grid>
            </bureauBlack:BureauBlackTheme>
    	</ScrollViewer>

As we discussed, the above xaml displays the Grid inside the theme.
Now one more thing when you add a theme to the page an assembly is automatically added to the reference and if you go ahead and check your Navigation: Page section you will find it.
 

xmlns:bureauBlack="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.BureauBlack"

Now our application is ready to go, press F5 to run the application and browse through the pages to find out different themes. I am providing different screenshot for your reference.

 

Image Loading


Theme: Bubble Creme
 

Image Loading

Theme: Bureau Black

 

Image Loading

Theme: Bureau Blue

 

Image Loading

Theme: Twilight Blue

 

Image Loading

My personal favourite are the Shiny Red and Rainier Orange themes, go ahead and choose best for your application.
Enjoy Coding.

 
Sign Up to vote for this article
 
About Author
 
dpatra
Occupation-Not Provided
Company-Not Provided
Member Type-Expert
Location-Not Provided
Joined date-13 Jul 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
    The color of the silverlight scroll bar was looking very ugly in one of my projects and it needs to be changed. Am so sure that the regular, default pale scroll bars suck most of the time. When the situation demands color tweaking for the scroll bar: Few simple steps and a few minutes of time, it’s done.
    Published Date : 15/Dec/2010
    Tilt an image on mouse move in Silverlight 3 (3D Animation)
    Published Date : 16/Feb/2010
    in this article, i will describe,How to use styles in Silverlight
    Published Date : 16/Feb/2010
    Every time you could have imagined for any background image for your application and for some controls. In Silverlight 2 and Silverlight 3 Beta it was not so easy to put Images as Background and do some Tiling. Using Tile Brush in Silverlight 3 we will be able to use images as background. In this article we will see how can we achieve that.
    Published Date : 08/Apr/2010
    We experienced styles in each and every control level. Now in Application Level we have some themes too.
    Published Date : 07/Apr/2010
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top