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/