0

我有一个网格控件,它已按列拆分。

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

我在第 0 列中有一个边框控件。但是我面临一个问题,即边框控件没有填充到该列的宽度。边框包含一个启用了环绕的文本块。如果文本块中的文本大于宽度,则它会被包裹并拉伸以填充可用空间。

但是,如果文本块包含只有大约 5-10 个字符的小文本,则边框控制不会延伸。

边框控件使用 Horizo​​ntalAlignment 和 VerticalAlignment 显式设置为 Stretch,Margin 为 0。但边框仍然没有拉伸到第 0 列中可用的空间?

4

4 回答 4

0

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

于 2012-08-14T13:18:32.260 回答
0

相信你的第一列不能

<ColumnDefinition />

相反,我认为应该是

<ColumnDefinition Width="*" />

ColumnDefinition.Width 是 GridLength 类型。GridLength 是一个结构,默认为“自动”。Auto 将尝试占用其子控件所需的最小空间。“*”的值表示相对于其他 * 列占用所有空间。(一列 2* 占用的空间是一列 1* 的两倍。我通常建议使用 1 到 100 之间的数字并将它们视为百分比)。由于没有其他列是 * 列,简单的“*”值表示占用所有剩余空间。

您会认为通过使所有其他列的宽度固定,它会强制第一列为“*”,但我认为情况并非如此。

您可以在此处阅读有关 GridLength 的更多信息:

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

于 2012-08-14T14:34:36.620 回答
0

请向我们展示您对边界的定义。它位于星型列中,但您可能已经给出了BorderaHorizontalAlignmentVerticalAlignment它会否定填充父级内容区域的默认行为。我已经验证了这个例子在 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>
于 2012-08-15T21:32:29.393 回答
-1
  <DataGridTemplateColumn Width="150">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Border HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch"
                                    BorderBrush="Red"
                                    BorderThickness="2">
                                <TextBlock Text="{Binding Name}" />
                            </Border>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
于 2012-08-14T12:02:48.700 回答