Blue Theme Orange Theme Green Theme Red Theme
 
Discover the top 5 tips for understanding .NET Interop
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 » Using the GridSplitter control in Silverlight

Using the GridSplitter control in Silverlight

In this article, you will learn how to work with the GridSplitter control of Silverlight 2.

Author Rank :
Page Views : 8632
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  
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Introduction

If you have ever worked with Microsoft Word then you will be able to understand what the GridSplitter looks like - it's exactly similar to the Splitter seen in Word that is used to split a document view into two panes.

The GridSplitter control in Silverlight allows the user to split a Grid column or row at runtime. Its basic purpose is to redistribute the available space by adjusting the rows or columns in width or height.

The GridSplitter class is defined in the System.Windows.Controls namespace.

Before you use this control, you must have a Grid existing with some rows and columns.

Let us now see how to use this control. Create a new Silverlight project named GridSplitterDemo.

Next, in the Design view of Page.xaml, define two rows and two columns within the default Grid and configure the properties of the Grid as shown below.

Page.xaml

<UserControl x:Class="GridSplitterDemo.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" ShowGridLines="True" Background="LemonChiffon" Width="400" Height="300">
        <Grid.RowDefinitions>
            <RowDefinition Height="200" />
            <RowDefinition Height="200" />
        </Grid.RowDefinitions>
<
Grid.ColumnDefinitions>
            <ColumnDefinition Width="150" />
            <ColumnDefinition Width="150" />
        </Grid.ColumnDefinitions>
    </Grid>
</
UserControl>

Modify the Page.xaml now so that it looks like below:

Page.xaml

<UserControl x:Class="GridSplitterDemo.Page"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" ShowGridLines="True" Background="LemonChiffon" Width="400" Height="300">
        <Grid.RowDefinitions>
            <RowDefinition Height="200" />
            <RowDefinition Height="200" />
        </Grid.RowDefinitions>
<
Grid.ColumnDefinitions>
            <ColumnDefinition Width="150" />
            <ColumnDefinition Width="150" />
        </Grid.ColumnDefinitions>
        <controls:GridSplitter x:Name="grsplSplitter" Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Background="IndianRed"  Width="5"></controls:GridSplitter>
    </Grid>
</
UserControl>

Here, you have defined a namespace named controls to reference the assembly System.Windows.Controls. Later, this namespace will be used when using the GridSplitter control.

The section

<controls:GridSplitter x:Name="grsplSplitter" Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Background="IndianRed"  Width="5"></controls:GridSplitter>

in Page.xaml defines the GridSplitter. It is placed in the first row and second column, and assigned a color, IndianRed, with horizontal alignment Center.

If you wish, you can also use the RowSpan or ColumnSpan properties to span the splitter across several rows or columns.

The ShowsPreview property (not shown here) allows you to specify whether you want to
show preview of the grid panes at runtime.

When you run the application, by selecting Debug-Start without Debugging in Visual Studio IDE, you will see the following output as shown



Figure 1

Conclusion: Thus, in this article, you learnt how to work with the GridSplitter control of Silverlight 2.


 

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:
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Comments
Mindcracker MVP Summit 2012
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.