如何在WPF中自动生成一个富文本框大小? [英] How to make a rich textbox automatically size in wpf?

查看:44
本文介绍了如何在WPF中自动生成一个富文本框大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使RichTextBox自动调整大小?我希望我的富文本框适合我分配给它的任何文本而没有滚动条.谢谢.

How to make a RichTextBox automatically size? I want my rich textbox to fit with any text I assign to it without having scroll bars. Thanks.

推荐答案

Horizo​​ntalAlignment VerticalAlignment 设置为除 Stretch 以外的其他选项(是默认设置).这将使TextBox缩小以适合其内容.如果您然后将其粘贴在具有 Horizo​​ntal Orientation StackPanel 内,它将不会垂直滚动,但会被其包含的面板剪切,我认为这是你在追求什么.如果要包含面板以将其自身调整为文本大小,则需要相应地配置面板

Set the HorizontalAlignment and VerticalAlignment to something other than Stretch (which is the default). This will make the TextBox shrink to fit its contents. If you then stick it inside a StackPanel with Orientation of Horizontal it will not scroll vertically but be clipped by its containing panel, which I think is what you are after. If you want you containing panel to resize itself to the text, then you need to configure the panel accordingly

这篇关于如何在WPF中自动生成一个富文本框大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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