901215-如何检索UserControl尺寸? [英] 901215 - how to retrieve UserControl dimensions?

查看:83
本文介绍了901215-如何检索UserControl尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我将图像放在用户控件的网格中.我已将图像的对齐方式设置为拉伸.因此图像的宽度和高度是自动设置的.在应用程序开始时,我需要知道图像的尺寸,但是它们是NaN,我不知道真正为它们分配了什么值.

我该怎么办?

thx

解决方案

问题是,ActualWidth和ActualHeight属性不是依赖项属性,因此您需要创建自己的属性,可以将其绑定到视图模型上. br/>
另外,如果以前的图像大小与当前大小不同,请在承载图像的用户控件和布局更新方法上创建自己的事件,请引发新的图像大小事件.

然后可以在视图模型中将其作为ICommand或某些类似的实现进行监听.


hi
i''ve an image in a grid in the user control. i''ve set alignments of the image as stretch. so width and height of the image are set automatically. at the beginning of application i need to know the dimensions of image, but they''re NaN and i can''t know what values are really assigned to them.

what can i do?

thx

解决方案

The problem is that the ActualWidth and ActualHeight properties are not dependency properties so you will need to created your own that can be bound to on the view model.

Alternatively, Create your own event on the user control that hosts the image, and on the layout updated method, if the previous image size is different from the current size, raise the new image size event.

This can then be listened for in the viewmodel as an ICommand, or some such implementation.


这篇关于901215-如何检索UserControl尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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