WPF:包装多部分文本

发布于 2024-08-19 09:07:48 字数 637 浏览 6 评论 0原文

目前我正在使用 TextBlock 来显示带有图像的单行。

<TextBlock>
    <Image Name="StatusImage"  Stretch="Fill" MaxWidth="12" MaxHeight="12"
           Source="/Aam.Cerberus.Applications;component/Images/Warning.png"></Image>
    <TextBlock Text="{Binding Path=ServiceStatusText}"></TextBlock>
    <TextBlock Text=" ("></TextBlock>
    <TextBlock Text="{Binding Path=ServiceMachineName}"></TextBlock>
    <TextBlock Text=")"></TextBlock>
</TextBlock>

我的问题是:

  1. TextBlock 是做这种事情的正确方法吗?
  2. 如何启用自动换行?

Currently I'm using a TextBlock to show a single line with an image.

<TextBlock>
    <Image Name="StatusImage"  Stretch="Fill" MaxWidth="12" MaxHeight="12"
           Source="/Aam.Cerberus.Applications;component/Images/Warning.png"></Image>
    <TextBlock Text="{Binding Path=ServiceStatusText}"></TextBlock>
    <TextBlock Text=" ("></TextBlock>
    <TextBlock Text="{Binding Path=ServiceMachineName}"></TextBlock>
    <TextBlock Text=")"></TextBlock>
</TextBlock>

My questions are:

  1. Is a TextBlock the right way to do this sort of thing?
  2. How do I enable word wrapping?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作妖 2024-08-26 09:07:48

您需要 TextWrapping="Wrap" 属性。

但是,根据 MSDN

TextBlock没有针对需要显示多行内容的场景进行优化;对于这种情况,FlowDocument 加上就性能而言,适当的查看控件是比 TextBlock 更好的选择。

You want the TextWrapping="Wrap" property.

However, according to the MSDN

TextBlock is not optimized for scenarios that need to display more than a few lines of content; for such scenarios, a FlowDocument coupled with an appropriate viewing control is a better choice than TextBlock, in terms of performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文