.net - WPF标签中的自动换行符

标签 .net wpf wpf-controls line-breaks

WPF Label是否有可能自动将自身拆分为几行?在下面的示例中,文本在右侧被裁剪。

<Window x:Class="..." xmlns="..." xmlns:x="..." Height="300" Width="300">
    <Grid>
        <Label>
            `_Twas brillig, and the slithy toves did gyre and gimble in the wabe:
            all mimsy were the borogoves, and the mome raths outgrabe.
        </Label>
    </Grid>
</Window>

难道我做错了什么?

不幸的是,采用其他控件并不是一个好的选择,因为我需要访问键的支持。

Label替换TextBlock(具有TextWrapping="Wrap"),并调整其控制模板以识别访问键可能是一种解决方案,但这不是一个过大的杀伤力吗?

编辑:具有非标准样式的标签会破坏皮肤,因此,如果可能的话,我想避免这种情况。

最佳答案

一起使用Label和TextBlock似乎是正确的答案。 There's a howto located here that demonstrates this exact issue.

具体来说,在他们的示例中,要获取换行文本和访问 key :

<Label Width="200" HorizontalAlignment="Left"
       Target="{Binding ElementName=textBox1}">
  <AccessText TextWrapping="WrapWithOverflow">
    _Another long piece of text that requires text wrapping
    goes here.
  </AccessText>
</Label>

关于.net - WPF标签中的自动换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2478312/

相关文章:

wpf - 水平或垂直 WPF 线限制为 125,000 像素?

wpf - VS 2012 扩展中的标准控件

WPF 复选框,如 StackOverflow 的 "accepted answer"复选框

wpf - 使用多种类型的控件搜索并突出显示 WPF 窗口上的任何文本

c# - 嵌套日期范围查询过滤器 ElasticSearch NEST C#

.net - SqlDataReader如何接收数据?

.net - 访问 Windows OpenSSH SFTP 服务器上的文件时出现错误 "Bad message"

c# - 最快的 StringBuilder 附加整数

wpf - 如何关闭 DrawingBrush 的抗锯齿功能?

c# - 在不创建新矩阵变换的情况下设置图像的布局变换