|
|
|
|
|
|
|
Author Rank :
|
|
|
Page Views :
|
10841
|
|
Downloads :
|
210
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
|
|
|
Download
Files:
|
|
|
|
|
|
|
|
|
|
|
|
Introduction:
Themes are like styles that you can apply to your Web pages. While ASP.NET 3.5 had ample support for styling through themes, Silverlight 2 itself does not include any built-in support for themes. This has been overcome now by the Silverlight Toolkit.
The Silverlight Toolkit is an open source community project hosted at www.codeplex.com.
A number of controls from the Toolkit have already been explained in various articles here.
In addition to these controls, the Silverlight Toolkit also provides themes.
In this article, we shall see how to use these themes with some amount of coding in the Page.xaml.cs file.
Before you begin, download the latest release of the Toolkit from www.codeplex.com. The December release should work fine. The November release of the Toolkit seems to cause some exceptions when themes are used. So make sure you download the December 08 (or later) release.
Once you have extracted the zip file into a desired folder on your PC, you will have folder structures similar to Figure 1, 2 and 3 for themes.

Figure 1: The main dll files for using the Silverlight Toolkit

Figure 2: Themes that are defined in the Toolkit

Figure 3: The XAML files for the themes
Now comes the step by step procedure to use themes in your application. Create a Silverlight 2 application having the following user interface:

Figure 4: UI for the application
The Page.xaml for this UI may look like below:
<UserControl x:Class="ThemeDemo.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls" xmlns:themes="clr-namespace:Microsoft.Windows.Controls.Theming;assembly=Microsoft.Windows.Controls.Theming" Width="400" Height="300"> <Grid Background="LemonChiffon" Width="300" Height="180" Name="LayoutRoot"> <Grid.ColumnDefinitions> <ColumnDefinition Width="150" /> <ColumnDefinition Width="150" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock Name="txtblkName" Grid.Row="0" Grid.Column="0" Text="Enter Customer Name:" Height="Auto" HorizontalAlignment="Left"> </TextBlock> <TextBox x:Name="txtName" Grid.Row="0" Grid.Column="1" Text="" > </TextBox> <TextBlock Name="txtblkAddr" Grid.Row="1" Grid.Column="0" Text="Enter Customer Address:" HorizontalAlignment="Left"> </TextBlock> <TextBox x:Name="txtAddr" Grid.Row="1" Grid.Column="1" Text="" > </TextBox> <TextBlock Grid.Row="4"></TextBlock> <Button Grid.Row="5" Grid.ColumnSpan="2" Content="Submit" HorizontalAlignment="Center"></Button> </Grid> </UserControl>
Once this is done, open the Page.xaml.cs and type in code similar to the below:
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 Microsoft.Windows.Controls.Theming;
namespace ThemeDemo { public partial class Page : UserControl { public Page() { InitializeComponent(); Loaded += new RoutedEventHandler(Page_Loaded); }
void Page_Loaded(object sender, RoutedEventArgs e) { Uri uri = new Uri(@"ThemeDemo;component/Microsoft.Windows.Controls.Theming.RainierOrange.xaml", UriKind.Relative); ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri); ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.Auto); ImplicitStyleManager.Apply(LayoutRoot); } } }
The ImplicitStyleManager class is defined in the Microsoft.Windows.Controls.Theming namespace and is a static class.
According to the available documentation in the Toolkit folder (look for the .chm file) the purpose of this class is to "encapsulate an attached behavior that propagates styles in a framework element's associated resource dictionary to its children". In simplest terms, it means that if you use this class and apply a theme to a layout container such as a Grid, all the contents of the Grid would have the same theme. This is a great concept!
Go to the Solution Explorer. Click References -> Add Reference and add references to all the dlls that were shown in Figure 1.
Copy the XAML file of the desired theme into your project folder and save it locally as part of your project.
Save, build and test the application. Ensure that you have replaced "ThemeDemo" in the above code with the name of your own application.
You will see that when the page is loaded, the RainierOrange theme is applied to all the contents of the Grid. Figure 5 shows a sample output.

Conclusion: Thus, in this article, you explored how to use themes from the Silverlight Toolkit.
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
Mamta M
Mamta M has over 8 years of experience in the IT industry and loves to learn and experiment with new technology trends. She is passionate about in C#, WPF, ASP.NET, Silverlight and other .NET related technologies. She believes knowledge grows through sharing and loves being active in the .NET community.
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|
|