Grid.SetColumnSpan Method

July 28, 2014

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
)

Parameters

element
Type: System.Windows.FrameworkElement
The element on which to set the Grid.ColumnSpan attached property.
value
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">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <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">
        <TextBlock>1</TextBlock>
        <TextBlock>2</TextBlock>
        <TextBlock>3</TextBlock>
    </ComboBox>
</Grid>



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

Show:
© 2014 Microsoft