【问题标题】:WPF Column Widths and a TextBlock SizingWPF 列宽和 TextBlock 大小
【发布时间】:2011-03-25 00:42:25
【问题描述】:

我在 xaml 中有一个网格,它有两列宽度分别为 4.5* 和 5.5*

在第 1 列中,我有一个文本块。当这个文本块的文本很长时,它会使文本块列非常宽,而我的第二列越来越小。

我需要 textblock 列保持设置的宽度并换行。

这里是 xaml:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="25"  />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="4.5*"/>
        <ColumnDefinition Width="5.5*"/>
    </Grid.ColumnDefinitions>
    <TextBlock x:Name="lblCheck" Text="{Binding Path=Text}"  Grid.Column="0"  Grid.Row="0" TextWrapping="Wrap" Margin="5,0,0,0"/>
    <CheckBox x:Name="chkOption" Grid.Column="1" IsChecked="{Binding Path=Checked}" Grid.Row="0"  IsEnabled="True"/>
</Grid>

谢谢

【问题讨论】:

  • 您发布的代码运行良好。如果它没有换行到第二行(行高限制)。那么问题可能出在其他地方。您的 Text 属性绑定到什么?我猜这个窗口还有更多内容?

标签: wpf grid textblock


【解决方案1】:

您发布的代码运行良好,除了您的 RowHeight 设置为 35,因此它最多只显示 2 行文本。

尝试将您的 RowHeight 设置为 *

【讨论】:

    【解决方案2】:

    如果您尝试将第 1 列的宽度设置为 4.5 并将第二列的宽度设置为 *

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-05
      • 2020-10-17
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 2017-04-06
      • 1970-01-01
      相关资源
      最近更新 更多