Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
GridSplitter Class

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
GridSplitter Class

Represents a control that redistributes space between the rows of columns of a Grid control.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)
Visual Basic (Declaration)
<TemplateVisualStateAttribute(Name := "Unfocused", GroupName := "FocusStates")> _
<StyleTypedPropertyAttribute(Property := "PreviewStyle", StyleTargetType := GetType(Control))> _
<TemplateVisualStateAttribute(Name := "Disabled", GroupName := "CommonStates")> _
<TemplatePartAttribute(Name := "VerticalTemplate", Type := GetType(FrameworkElement))> _
<TemplatePartAttribute(Name := "HorizontalTemplate", Type := GetType(FrameworkElement))> _
<TemplateVisualStateAttribute(Name := "MouseOver", GroupName := "CommonStates")> _
<TemplateVisualStateAttribute(Name := "Normal", GroupName := "CommonStates")> _
<TemplateVisualStateAttribute(Name := "Focused", GroupName := "FocusStates")> _
Public Class GridSplitter _
    Inherits Control
Visual Basic (Usage)
Dim instance As GridSplitter
C#
[TemplateVisualStateAttribute(Name = "Unfocused", GroupName = "FocusStates")]
[StyleTypedPropertyAttribute(Property = "PreviewStyle", StyleTargetType = typeof(Control))]
[TemplateVisualStateAttribute(Name = "Disabled", GroupName = "CommonStates")]
[TemplatePartAttribute(Name = "VerticalTemplate", Type = typeof(FrameworkElement))]
[TemplatePartAttribute(Name = "HorizontalTemplate", Type = typeof(FrameworkElement))]
[TemplateVisualStateAttribute(Name = "MouseOver", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Normal", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Focused", GroupName = "FocusStates")]
public class GridSplitter : Control
XAML Object Element Usage
<controls:GridSplitter .../>

XAML Values

controls:

A prefix that is defined to map the XML namespace for the System.Windows.Controls assembly and the System.Windows.Controls CLR namespace.

The precise manner in which space in the Grid is redistributed when you use a GridSplitter is controlled by the properties of the grid columns. For more information, see Grid.

Once a GridSplitter is put into a cell on a Grid, it can be used to resize rows or columns either vertically or horizontally. To specify whether a GridSplitter resizes rows or columns, use the HorizontalAlignment and VerticalAlignment attached properties. One of these two properties should always be set to Stretch. The following table summarizes the possibilities:

HorizontalAlignment

VerticalAlignment

Result

Stretch

Other

Resizes rows.

Other

Stretch

Resizes columns.

Stretch

Stretch

Resizes columns if ActualHeight is greater than or equal to ActualWidth; otherwise, resizes rows.

NoteNote:

The GridSplitter control is available as part of the libraries in the Silverlight Software Development Kit (SDK). For more information, see the Silverlight Tools.

Customizing the GridSplitter Control

To apply the same property settings to multiple GridSplitter controls, use the Style property. To change the visual structure and visual behavior of a GridSplitter, copy and modify its default style and template. For more information, see Control Customization.

If a dependency property for a GridSplitter is set by its default style, the property might change from its default value when the GridSplitter appears in the application. For more information, see Dependency Property Value Precedence. You can get the default style and template for GridSplitter from GridSplitter Styles and Templates.

NoteNote:

Setting a visual property will only have an effect if that property is both present in GridSplitter control's default template and is set by using a TemplateBinding. You can find a list of visual properties in the "Changing the Visual Structure of a Control" section of Customizing the Appearance of an Existing Control by Using a ControlTemplate.

The following XAML creates two GridSplitter controls, one vertical and one horizontal. The horizontal control shows a preview, whereas the vertical one does not.

Run this sample

<UserControl x:Class="GridSplitterExample.Page"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:swc="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"             
        Width="450"
        Height="500"
        >

    <Canvas x:Name="LayoutRoot" Background="White" >
        <TextBlock Text="GridSplitter Demonstration" Margin="0,20,10,20"
            FontFamily="Verdana" FontSize="18" FontWeight="Bold"
            Foreground="#FF5C9AC9" Canvas.Top="0" Canvas.Left="20"/>
        <Grid ShowGridLines="True" Canvas.Top="60" Canvas.Left="20" Width="400" Height="400">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>



            <TextBlock Text="One!" Grid.Row="0" Grid.Column="0" />
            <TextBlock Text="Two!" Grid.Row="1" Grid.Column="1" />
            <TextBlock Text="Three!" Grid.Row="2" Grid.Column="2" />
            <TextBlock Text="Four!" Grid.Row="3" Grid.Column="3" />
            <swc:GridSplitter Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4"
                               Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                               ShowsPreview="True"
                                />
            <swc:GridSplitter Grid.Row="2" Grid.Column="1" Grid.RowSpan="2"
                               Width="5" HorizontalAlignment="Left" VerticalAlignment="Stretch"
                                />
       </Grid>


    </Canvas>
</UserControl>

The previous example produces output that is similar to the following illustration. A grid is shown before and after a GridSplitter is used to redistribute space.

Silverlight GridSplitter control
System..::.Object
  System.Windows..::.DependencyObject
    System.Windows..::.UIElement
      System.Windows..::.FrameworkElement
        System.Windows.Controls..::.Control
          System.Windows.Controls..::.GridSplitter
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker