Blue Theme Orange Theme Green Theme Red Theme
 
Nevron Chart
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » Silverlight » Working with Silverlight Toolkit: Part II

Working with Silverlight Toolkit: Part II

The Silverlight Toolkit provides a variety of rich controls to supplement the existing Silverlight controls. This article describes how to add the Toolkit controls to your Toolbox and make use of the AutoCompleteBox control.

Author Rank :
Page Views : 4288
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
DevExpress Free UI Controls
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Objective:
In the next part of this series, we shall explore how to add the Silverlight Toolkit to your application and how to create the AutoCompleteBox control.

Let's go through this step by step. We will begin with creating a new Silverlight application using Visual C#. Consider that the scenario involves a Web portal for a car rental system. Assume that this the user interface of this Web application will require an AutoCompleteBox for the car manufacturer name. For the purpose of this article, let's just focus on this single field, without considering the rest of the UI.

We create the new application and name it AutoCompleteCars as shown in Figure 1.



Figure 1: Creating the Silverlight application

Next, we download the Silverlight Toolkit from the codeplex site. The link for download is:

http://www.codeplex.com/Silverlight/Release/ProjectReleases.aspx?ReleaseId=18804

Actually we can even download the Toolkit before creating the Silverlight application, that's upto us, whether to do it, before or after.

After downloading the zip file, extract the contents into a folder.

In the newly created application, to view and use the Toolkit controls, we have to follow certain steps.

We open the Toolbox and right click on it. In the shortcut menu that opens as shown in Figure 2, we select the Choose Items... option.



Figure 2: Toolbox shortcut menu

This will launch the Choose Toolbox Items dialog box. We select the Silverlight Components tab in the dialog box.



Figure 3: Selecting the Silverlight Components tab

Then we click Browse because we want to select the dll for the Toolkit. We navigate to the folder where we'd installed the Toolkit files. We select the Microsoft.Windows.Controls.dll file as shown in Figure 4.



Figure 4: Choosing the dll file for the Silverlight Toolkit controls

Once the dll file has been chosen, the Choose Toolbox Items dialog box shows the available controls in the Toolkit. Figure 5 and 6 depict these.



Figure 5: Silverlight Controls



Figure 6: More Silverlight Controls

We click OK to finish the task of adding the Toolkit to our Toolbox.



Figure 7: Silverlight Toolkit Controls as seen in the Toolbox

Now, we are ready to use these controls in your Silverlight application.

When we open the Page.xaml file of AutoCompleteCars, we will observe the following code:

      <UserControl xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
 x:Class="AutoCompleteCars.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="550" Height="300">

The lines marked in bold indicate the new changes, which have taken place after we included the Toolkit controls.

Next, we edit the Page.xaml file of AutoCompleteCars so that it looks like the following code:

    <Grid x:Name="LayoutRoot" Background="Pink" Width="370" Height="100">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="150" />
                <ColumnDefinition Width="170" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
        </Grid>

We place the cursor at the line above </Grid> and insert a blank line. At this position in the code, from the Toolbox, we drag and drop the TextBlock control. Thereafter, we drag and drop the AutoCompleteBox control. Then we edit their properties so that the code looks like the following:

       <TextBlock Grid.Row="0" Grid.Column="0" Name="txtblkCars" Width="150" Height="55" Text="Enter Car Manufacturer:" Margin="10" HorizontalAlignment="Left">
</
TextBlock>
        <controls:AutoCompleteBox Name="autocomCars" Height="25" Width="140" Grid.Row="0" Grid.Column="1" Margin="10" VerticalAlignment="top">
        </controls:AutoCompleteBox>

The complete code for Page.xaml now looks like below:

     <UserControl xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls" x:Class="AutoCompleteCars.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="550" Height="300">
            <Grid x:Name="LayoutRoot" Background="Pink" Width="370" Height="100">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="150" />
                    <ColumnDefinition Width="170" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Name="txtblkCars" Width="150" Height="55" Text="Enter Car Manufacturer:" Margin="10" HorizontalAlignment="Left"></TextBlock>
                <controls:AutoCompleteBox Name="autocomCars" Height="25" Width="140" Grid.Row="0" Grid.Column="1" Margin="10" VerticalAlignment="top"></controls:AutoCompleteBox>
            </Grid>
        </UserControl>

We save the file and switch to the codeview, that is, Page.xaml.cs file. Within the constructor, we add the line marked in bold.

public Page()
{
InitializeComponent();
autocomCars.ItemsSource = new string[] {"Lexus", "Land Rover", "Ford", "Porsche","Pontiac", "Ferrari", "Fiat" };
}

Then we save the .cs file and proceed to build the application. Upon successful build, we click Debug->Start Debugging (or press F5).

A sample output of the application is shown in Figure 8.



Figure 8: AutoCompleteBox in action

Conclusion

Thus, we explored step by step how to add the Silverlight Toolkit controls to an application and how to use the AutoCompleteBox control.
 

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
 [Top] Rate this article
 
 About the author
 
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.
Looking for C# Consulting?
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.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
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!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
Mindcracker MVP Summit 2012
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.