WPF标签中的自动换行符

Vla*_*lad 7 .net wpf line-breaks wpf-controls

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>
Run Code Online (Sandbox Code Playgroud)

难道我做错了什么?

遗憾的是,采取其他控制措施不是一个好选择,因为我需要支持访问密钥.

替换Labela TextBlock(有TextWrapping="Wrap"),并调整其控制模板以识别访问密钥可能是一个解决方案,但它不是一个矫枉过正吗?

编辑:标签的非标准样式会破坏皮肤,所以我想尽可能避免它.

Ben*_*orf 11

同时使用Label和TextBlock似乎是正确的答案. 这里有一个howto来演示这个确切的问题.

具体来说,在他们的示例中,要获取包装文本和访问密钥:

<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>
Run Code Online (Sandbox Code Playgroud)