WPF - 图像控件实际大小

标签 wpf image controls actualwidth actualheight

我在获取 WPF 中图像控件的 ActualHeightActualWidth 时遇到问题。当用户选择图像文件时,我想根据图像控件的尺寸调整所选图像的大小。

我试图在窗口初始化时获取 Image.ActualHeightImage.ActualWidth,但我发现 Image 控件的两个属性都是“0”。

那么如何获取图片控件的尺寸呢。

最佳答案

FrameworkElement.ActualHeight的备注说在属性(property)具有其真正值(value)之前可能会有一些滞后。

This property is a calculated value based on other height inputs, and the layout system. The value is set by the layout system itself, based on an actual rendering pass, and may therefore lag slightly behind the set value of properties such as Height that are the basis of the input change.

控件的最终大小由 FrameworkElement.Arrange(-Override) 设置.您可以覆盖该方法并只调用基类实现。它的返回值将是您图片的实际大小。

关于WPF - 图像控件实际大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3236635/

相关文章:

c# - MVVM 中的 ViewModel 是什么

wpf - 屏蔽到 WPF 日期选择器

ios - 使用 Assets 路径或本地文件路径显示图像

ios - 如何在 TextKit 中调整图像/附件的大小和布局?

Java从网页中获取单个元素

VB.NET:代码不检查面板中是否存在控件

wpf - 禁用 WPF 标签加速键(缺少文本下划线)

c# - 让我的第二个水平网格分离器正常工作

jquery - 如何使用 jQuery 单击图像来查找图像的名称?

c# - 如何轻松隐藏 UWP MediaPlayerElement 中除少数几个之外的所有传输控件?