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

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

问题描述

我目前正在 WPF 中使用 Panels,我注意到关于 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.

实际宽度

获取此渲染的宽度元素.这是一个依赖财产.(继承自框架元素.)

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/ActualHeightRenderSize.Width/RenderSize.Height 都返回元素的渲染大小,如RenderSizeSize 类型.如果您想要/需要商品的实际尺寸,请使用这些属性中的任何一个.

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天全站免登陆