0
votes

I have a grid control where it has been split Column wise.

<Grid HorizontalAlignment="Stretch">
    <Grid.ColumnDefinitions>
         <ColumnDefinition />
         <ColumnDefinition Width="80" />
         <ColumnDefinition Width="65" />
    </Grid.ColumnDefinitions>
</Grid>

I have a border control inside column 0. However I am facing an issue that border control is not filling upto the width of this column. The border contains a textblock with Wrapping enabled. if the text in textblock is bigger than width, then it gets wrapped and it stretches to fill available space.

However, if the text block contains small text which is of around 5-10 characters only, then border control does not stretches.

The border control is explicitly set with HorizontalAlignment and VerticalAlignment as Stretch and Margin as 0. but still the border doesn't stretch to what the space is available in column 0?

4
Can you post the definition for the Border here?XAMeLi

4 Answers

0
votes

Try setting the width of the border. If you want to let the border take up the space then set the ColumnDefinition to * (First)

0
votes

I believe your first column cannot be

<ColumnDefinition />

Instead I think it should be

<ColumnDefinition Width="*" />

ColumnDefinition.Width is of type GridLength. GridLength is a structure and it defaults to "Auto". Auto will try to take up the minimal amount of space that its child controls need. A value of "*" means take all space relative to other * columns. (A column of 2* would take up twice as much space as a column of 1*. I usually recommend using numbers between 1 and 100 and thinking of them as percentages). Since no other columns are * columns, a value of simple "*" means take up all remaining space.

You would think that by having all other columns fixed width it would force the first column to be "*", but I don't think that's the case.

You can read more about GridLength here:

http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.gridlength.aspx

0
votes

Please show us your definition of the Border. It is in a Star-sized column but you may have given the Border a HorizontalAlignment or VerticalAlignment which would negate the default behavior to fill the parent's content area. I have verified this example works fine in Kaxaml.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="80"/>
            <ColumnDefinition Width="65"/>
        </Grid.ColumnDefinitions>
        <Border Background="LightGreen"/>
        <TextBlock Grid.Column="1" Foreground="Blue" Text="Column01"/>
        <TextBlock Grid.Column="2" Foreground="Red" Text="Column02"/>
    </Grid>
</Page>
-1
votes
  <DataGridTemplateColumn Width="150">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Border HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch"
                                    BorderBrush="Red"
                                    BorderThickness="2">
                                <TextBlock Text="{Binding Name}" />
                            </Border>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>