Export (0) Print
Expand All

GridSplitter Class

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

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[StyleTypedPropertyAttribute(Property="PreviewStyle", StyleTargetType=typeof(Control))] 
public class GridSplitter : Thumb
/** @attribute StyleTypedPropertyAttribute(Property="PreviewStyle", StyleTargetType=System.Windows.Controls.Control) */ 
public class GridSplitter extends Thumb
StyleTypedPropertyAttribute(Property="PreviewStyle", StyleTargetType=System.Windows.Controls.Control) 
public class GridSplitter extends Thumb
<GridSplitter .../>

The GridSplitter control redistributes space between rows or columns in a Grid, without changing the dimensions of the Grid. For example, when a GridSplitter resizes two columns, the ActualWidth property of one column is increased while at the same time the ActualWidth property of the other column is decreased by the same amount.

The following table shows how to define a horizontal or vertical GridSplitter by setting the HorizontalAlignment and VerticalAlignment properties and by leaving the ResizeDirection and ResizeBehavior properties set to their default values.

How to create vertical and horizontal GridSplitter controls

GridSplitter Type

HorizontalAlignment value

VerticalAlignment value

Resizes rows(horizontal)

Left, Right, Center

Stretch

Resizes columns(vertical)

Stretch

Top, Bottom, Center

If ActualHeight is greater than or equal to ActualWidth,this resizes the rows (horizontal).

If ActualHeight is less than ActualWidth,this resizes the columns (vertical).

Stretch

Stretch

A GridSplitter can overlap a row or column that contains other content, or can occupy a row or column by itself. For more information about how to define a GridSplitter, see How to: Resize Rows with a GridSplitter and How to: Resize Columns with a GridSplitter.

If the HorizontalAlignment and VerticalAlignment property settings do not achieve the desired GridSplitter behavior, you can change the ResizeDirection and ResizeBehavior property settings.

A GridSplitter may be obscured by other objects that are contained in the Children collection of the Grid. For information about how to prevent this situation, see How to: Make sure that a GridSplitter is Visible.

The following example shows how to define a GridSplitter that resizes columns in a Grid by overlaying the edge of a column.

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition/>
    <ColumnDefinition/>
  </Grid.ColumnDefinitions>
  <GridSplitter Grid.Column ="0" Background="Blue" 
                HorizontalAlignment="Right" VerticalAlignment="Stretch"/>
</Grid>

GridSplitter mySimpleGridSplitter = new GridSplitter();
Grid.SetColumn(mySimpleGridSplitter, 0);
mySimpleGridSplitter.Background = Brushes.Blue;
mySimpleGridSplitter.HorizontalAlignment = HorizontalAlignment.Right;
mySimpleGridSplitter.VerticalAlignment = VerticalAlignment.Stretch;
mySimpleGridSplitter.Width = 5;

The following example shows how to define a GridSplitter that resizes columns in a Grid and that occupies a column in the Grid.

      <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition/>
      </Grid.ColumnDefinitions>

...

      <GridSplitter Grid.Column="1"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Stretch"
                    Background="Black" 
                    ShowsPreview="True"
                    Width="5"
                    />

More Code

How to: Resize Rows with a GridSplitter

This example shows how to use a horizontal GridSplitter to redistribute the space between two rows in a Grid without changing the dimensions of the Grid.

How to: Resize Columns with a GridSplitter

This example shows how to create a vertical GridSplitter in order to redistribute the space between two columns in a Grid without changing the dimensions of the Grid.

How to: Make Sure That a GridSplitter Is Visible

This example shows how to make sure a GridSplitter control is not hidden by the other controls in a Grid.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Controls.Control
               System.Windows.Controls.Primitives.Thumb
                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.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft