WPF 中的 Width 和 ActualWidth 有什么区别? [英] What is the difference between Width and ActualWidth in WPF?
问题描述
我目前正在 WPF 中使用 Panel
s,我注意到关于 Width
和 Height
属性,还有两个其他名为 ActualWidth
和 ActualHeight
的属性.
I am currently working with Panel
s in WPF, and I noticed that as regards the Width
and Height
properties, there are also two other properties called ActualWidth
and ActualHeight
.
实际宽度
获取此渲染的宽度元素.这是一个依赖财产.(继承自框架元素.)
Gets the rendered width of this element. This is a dependency property. (Inherited from FrameworkElement.)
宽度
获取或设置元素的宽度.这是一个依赖属性.(继承自 FrameworkElement.)
Gets or sets the width of the element. This is a dependency property. (Inherited from FrameworkElement.)
参考:MSDN
谁能指出两者之间的区别以及何时使用其中之一?
推荐答案
Width
/Height
是请求或布局的大小.如果您设置为 Auto,则当您访问代码隐藏的属性时,该值是 double.NaN
.
Width
/Height
is the requested or layout size. If you set to Auto, then the value is double.NaN
when you access the property in code behind.
ActualWidth
/ActualHeight
和 RenderSize.Width
/RenderSize.Height
都返回元素的渲染大小,如RenderSize 是 Size 类型.如果您想要/需要商品的实际尺寸,请使用这些属性中的任何一个.
ActualWidth
/ActualHeight
and RenderSize.Width
/RenderSize.Height
both return the element's rendered size, as RenderSize is of type Size. If you want/need the actual size of the item, then use any of these attributes.
这篇关于WPF 中的 Width 和 ActualWidth 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!