Partager via


Grid.SetColumnSpan Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Shared Sub SetColumnSpan ( _
    element As FrameworkElement, _
    value As Integer _
)
public static void SetColumnSpan(
    FrameworkElement element,
    int value
)

Parameters

Remarks

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

Examples

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

Run this sample

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

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

Platforms

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