10

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>

难道我做错了什么?

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

将 替换LabelTextBlock(have TextWrapping="Wrap"),并调整其控制模板以识别访问键可能是一种解决方案,但这不是矫枉过正吗?

编辑:标签的非标准样式会破坏蒙皮,所以如果可能的话,我想避免它。

4

1 回答 1

13

同时使用 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>
于 2010-03-19T15:19:50.940 回答