我怎样才能在包装使用WPF标签的文本? [英] How can I wrap text in a label using WPF?

查看:150
本文介绍了我怎样才能在包装使用WPF标签的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 文本框 和标签。点击一个按钮后,我执行下面的代码:

I have a TextBox and a Label. After clicking a button, I execute the following code:

 label1.Content = textbox1.Text; 



我的问题是,如何使标签的文字环绕?有可能会在一行上显示太多的文字,我想它会自动换到多行,如果是这样的话。

My question is, how do I enable text wrapping of the label? There may be too much text to display on one line, and I want it to automatically wrap to multiple lines if that is the case.

推荐答案

标签控制不直接支持WPF文本换行。您应该使用 的TextBlock 来代替。 (当然,你可以把的TextBlock 的一个标签的控制,如果你。祝)

The Label control doesn't directly support text wrapping in WPF. You should use a TextBlock instead. (Of course, you can place the TextBlock inside of a Label control, if you wish.)

示例代码:

<TextBlock TextWrapping="WrapWithOverflow">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec adipiscing
    nulla quis libero egestas lobortis. Duis blandit imperdiet ornare. Nulla
    ac arcu ut purus placerat congue. Integer pretium fermentum gravida.
</TextBlock>

这篇关于我怎样才能在包装使用WPF标签的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆