Grid.SetColumnSpan Method


Sets the value of the Grid.ColumnSpan attached property to the specified FrameworkElement.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

public static void SetColumnSpan(
	FrameworkElement element,
	int value


Type: System.Windows.FrameworkElement
The element on which to set the Grid.ColumnSpan attached property.
Type: System.Int32
The property value to set.

Call SetColumnSpan to set the number of columns that an element's layout slot fills.

The following example shows how to use SetColumnSpan to change how an element is displayed.

Run this sample

<Grid x:Name="LayoutRoot" ShowGridLines="True">
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto"/>
    <TextBlock x:Name="txt1" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1" Text="This text can span multiple columns" FontSize="16" TextWrapping="Wrap" />
    <TextBlock Grid.Row="1" Text="Select the ColumnSpan"/>
    <ComboBox Grid.Column="1" Grid.Row="1" SelectedIndex="0" SelectionChanged="ComboBox_SelectionChanged">

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    if (txt1 != null)
        ComboBox box = (ComboBox)sender;
        int index = (sender as ComboBox).SelectedIndex;
        Grid.SetColumnSpan(txt1, index + 1);


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

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

Community Additions