设置为“自动”时获取WPF控件高度

时间:2022-11-13 10:10:25

I need get a WPF control height for calculate my next control margin top, but when I try get control height with textbox1.height, this is return 'Auto' and not numbers

我需要获得一个WPF控制高度来计算我的下一个控制边缘顶部,但是当我尝试使用textbox1.height获得控制高度时,这将返回'Auto'而不是数字

What can I do for get control height, when it is set 'Auto'?

当设置为“自动”时,我可以做什么来获得控制高度?

1 个解决方案

#1


7  

You should try this:

你应该试试这个:

textBox1.ActualHeight

Remarks (by @Viv)

备注(@Viv)

just make sure when you query for textBox1.ActualHeight, you do it once the control is Loaded. You're going to get 0.0 if you check ActualHeight before it's setup properly

只需确保在查询textBox1.ActualHeight时,您可以在控件加载后执行此操作。如果在正确设置之前检查ActualHeight,您将获得0.0

#1


7  

You should try this:

你应该试试这个:

textBox1.ActualHeight

Remarks (by @Viv)

备注(@Viv)

just make sure when you query for textBox1.ActualHeight, you do it once the control is Loaded. You're going to get 0.0 if you check ActualHeight before it's setup properly

只需确保在查询textBox1.ActualHeight时,您可以在控件加载后执行此操作。如果在正确设置之前检查ActualHeight,您将获得0.0