代码中的 WPF 自动高度 [英] WPF Auto height in code

查看:23
本文介绍了代码中的 WPF 自动高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 C# 代码中 WPF 控件的 Height 属性的值设置为Auto"?

How could I set the value of the Height property of a WPF control in C# code to "Auto"?

<Grid.RowDefinitions>
    <RowDefinition />
    <RowDefinition Height="Auto" />
    <RowDefinition />
    <RowDefinition Height="Auto" />
    <RowDefinition />
    <RowDefinition Height="Auto" />
    <RowDefinition />
    <RowDefinition Height="Auto" />
    <RowDefinition />
</Grid.RowDefinitions>

我想在后面的代码中重现这种行为.有什么想法吗?

I want to reproduce this behavior in the code behind. Any ideas?

推荐答案

也许 此链接 将帮助您.

有时,您可能想要以编程方式设置高度或要自动输入的 WPF 元素的宽度代码.为此,只需使用Double.NaN(非数字)值.

At times, you may want to programmatically set the Height or Width of a WPF element to Auto in code. To do this, just use the Double.NaN (Not a Number) value.

例如,在 C# 中:

this.txtName.Width = Double.NaN;

this.txtName.Width = Double.NaN;

这篇关于代码中的 WPF 自动高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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