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.
Assembly: System.Windows (in System.Windows.dll)
'Declaration Public Shared Sub SetColumnSpan ( _ element As FrameworkElement, _ value As Integer _ )
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.
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); } }
Show: