Wpf控制内容的大小? [英] Wpf control size to content?

查看:25
本文介绍了Wpf控制内容的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 WPF 控件根据其中的内容改变其大小?

How do I make a WPF control to change its size according the content in it?

推荐答案

对于大多数控件,您在 XAML 中将其高度和宽度设置为 Auto,并且它会调整大小以适合其内容.

For most controls, you set its height and width to Auto in the XAML, and it will size to fit its content.

在代码中,您将宽度/高度设置为 double.NaN.有关详细信息,请参阅 FrameworkElement.Width,特别是备注"部分.

In code, you set the width/height to double.NaN. For details, see FrameworkElement.Width, particularly the "remarks" section.

这篇关于Wpf控制内容的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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