* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
3.4 KiB
title, ms.date, helpviewer_keywords, ms.assetid
| title | ms.date | helpviewer_keywords | ms.assetid | |||
|---|---|---|---|---|---|---|
| How to: Resize Columns with a GridSplitter | 03/30/2017 |
|
47b20fe6-7adc-4aa6-9693-b4e184eef74b |
How to: Resize Columns with a GridSplitter
This example shows how to create a vertical xref:System.Windows.Controls.GridSplitter in order to redistribute the space between two columns in a xref:System.Windows.Controls.Grid without changing the dimensions of the xref:System.Windows.Controls.Grid.
Example
How to create a GridSplitter that overlays the edge of a column
To specify a xref:System.Windows.Controls.GridSplitter that resizes adjacent columns in a xref:System.Windows.Controls.Grid, set the xref:System.Windows.Controls.Grid.Column%2A attached property to one of the columns that you want to resize. If your xref:System.Windows.Controls.Grid has more than one row, set the xref:System.Windows.Controls.Grid.RowSpan%2A attached property to the number of rows. Then set the xref:System.Windows.FrameworkElement.HorizontalAlignment%2A property to xref:System.Windows.HorizontalAlignment.Left or xref:System.Windows.HorizontalAlignment.Right (which alignment you set depends on which two columns you want to resize). Finally, set the xref:System.Windows.FrameworkElement.VerticalAlignment%2A property to xref:System.Windows.VerticalAlignment.Stretch.
[!code-xamlGridSplitterRowColumn#GridSplitterColumnOverlay]
A xref:System.Windows.Controls.GridSplitter that does not have its own column may be obscured by other controls in the xref:System.Windows.Controls.Grid. For more information about how to prevent this issue, see Make Sure That a GridSplitter Is Visible.
How to create a GridSplitter that occupies a column
To specify a xref:System.Windows.Controls.GridSplitter that occupies a column in a xref:System.Windows.Controls.Grid, set the xref:System.Windows.Controls.Grid.Column%2A attached property to one of the columns that you want to resize. If your Grid has more than one row, set the xref:System.Windows.Controls.Grid.RowSpan%2A attached property to the number of rows. Then set the xref:System.Windows.FrameworkElement.HorizontalAlignment%2A to xref:System.Windows.HorizontalAlignment.Center, set the xref:System.Windows.FrameworkElement.VerticalAlignment%2A property to xref:System.Windows.VerticalAlignment.Stretch, and set the xref:System.Windows.Controls.ColumnDefinition.Width%2A of the column that contains the xref:System.Windows.Controls.GridSplitter to xref:System.Windows.GridLength.Auto%2A.
The following example shows how to define a vertical xref:System.Windows.Controls.GridSplitter that occupies a column and resizes the columns on either side of it.
[!code-xamlGridSplitterRowColumn#GridSplitterEntireColumnPart1]
[!code-xamlGridSplitterRowColumn#GridSplitterEntireColumnPart2]