SetColumnSpan Method

Grid.SetColumnSpan Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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.

<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);

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2016 Microsoft