【问题标题】:TextBlock when run not displaying entire text运行时TextBlock不显示整个文本
【发布时间】:2019-03-20 09:21:46
【问题描述】:

我正在构建一个 wpf 应用程序,其中我的文本块文本在应用程序运行时淡出。 代码是

<Grid>
        <TextBlock Text="RSP Level" Width="78" Height="Auto" HorizontalAlignment="Left" Margin="54.2,3,0,398.6" Grid.Column="3"/>
        <TextBlock Text="Hex" Width="60" Height="Auto" HorizontalAlignment="Left" Grid.Column="3" Margin="157.2,36,0,367.6" RenderTransformOrigin="0.993,0.976" Grid.ColumnSpan="2"/>
        <TextBlock Text="Hex" Width="29" Height="20" TextWrapping="Wrap" HorizontalAlignment="Left" Grid.Column="3" Margin="31.2,35,0,368.6" RenderTransformOrigin="1.91,0.08" />
        <TextBlock Text="Link" Width="29" Height="20" HorizontalAlignment="Left" Grid.Column="3" Margin="31.2,59,0,344.6" RenderTransformOrigin="0.993,0.976"/>
        <TextBlock Text="Application" Width="61" Height="20" HorizontalAlignment="Left" Grid.Column="3" Margin="32.2,83,0,320.6" RenderTransformOrigin="0.993,0.976"/>
        <TextBlock Text="Physical" Width="66" Height="Auto" HorizontalAlignment="Left" Grid.Column="3" Margin="158.2,61,0,342.6" RenderTransformOrigin="0.993,0.976" Grid.ColumnSpan="2"/>
        <TextBlock Text="Link" Width="35" Height="Auto" HorizontalAlignment="Left" Grid.Column="3" Margin="158.2,85,0,318.6" RenderTransformOrigin="0.993,0.976"/>
        <TextBlock Text="Application" Width="69" Height="Auto" HorizontalAlignment="Left" Grid.Column="3" Margin="157.2,108,0,295.6" RenderTransformOrigin="0.993,0.976" Grid.ColumnSpan="2"/>
    </Grid>

【问题讨论】:

  • 尝试为文本块设置 `Height="Auto"。
  • @ChetanRanpariya 我试过自动,同样的结果..
  • 我无法重现该问题。您的代码在我身边运行良好。请提供MCVE
  • 显示完整代码。您缺少 ColumnDefinitions 和 CheckBoxes...使用嵌套的 StackPanels 或将 RowDefinitions 添加到您的网格中。然后,一行的每一列都包含一个水平 StackPanel,其中包含一个 TextBlock 和一个 CheckBox。为此,您需要两列。
  • 感谢大家的帮助。我将文本块分组在堆栈面板中,效果很好。

标签: c# wpf wpf-controls textblock


【解决方案1】:

这不是对齐内容的正确方法。您可以使用StackPanel 将子元素放置在彼此下方或旁边。如果您使用Grid,请定义行和列。使用边距不是正确的方法。阅读更多关于布局的 WPF here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 2011-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多