WPF中的Width和ActualWidth有什么区别? [英] What is the difference between Width and ActualWidth in WPF?

查看:560
本文介绍了WPF中的Width和ActualWidth有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在WPF中使用Panel,并且我注意到关于WidthHeight属性,还有两个其他属性,分别称为ActualWidthActualHeight.

I am currently working with Panels 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/ActualHeightRenderSize.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屋!

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