WPF中的Width和ActualWidth有什么区别? [英] What is the difference between Width and ActualWidth in WPF?
问题描述
我目前正在WPF中使用Panel
,并且我注意到关于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
.
ActualWidth
获取此对象的渲染宽度 元素.这是一个依赖 财产. (继承自 FrameworkElement.)
Gets the rendered width of this element. This is a dependency property. (Inherited from FrameworkElement.)
Width
获取或设置元素的宽度. 这是一个依赖属性. (继承自FrameworkElement.)
Gets or sets the width of the element. This is a dependency property. (Inherited from FrameworkElement.)
参考: MSDN
谁能指出两者之间的区别以及何时使用其中任何一个?
推荐答案
Width
/Height
是请求的大小或布局.如果设置为自动",则在后面的代码中访问属性时,该值为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屋!