询问者
填充与Grid中某一列的Image如何获取宽度和高度?

问题
-
布局很简单,Grid分成两列,指定Image位于第1列,此时Image默认填满整列空间。
现在要获取显示的Image的Width和Height,然后在内存中创建相同大小的WriteableBitmap,问题来了:
由于没有指定Image控件的Width和Height,Image在没有设置Source之前Width和Height都是NaN,ActualWidth和ActualHeight的值都是0. 如何获取Image填满整列空间时的大小?
<audio controls="controls" style="display:none;"></audio>
全部回复
-
-
Hi ShannonZhou,
>>由于没有指定Image控件的Width和Height,Image在没有设置Source之前Width和Height都是NaN,ActualWidth和ActualHeight的值都是0. 如何获取Image填满整列空间时的大小?
当你运行程序后,你是可以用ActualWidth和ActualHeight获取Image的具体值的。
所以不清楚你是想怎么获取?在设计UI的时候,就需要获取值,并绑定给其他对象?这个也是可以获取到ActualWidth和ActualHeight的。
Best Regards
Yong LuMSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
Image没有设置Soure,所以ActualXX得到的都是NaN<audio controls="controls" style="display:none;"></audio>
Hi ShannonZhou,
那你这个大小在设计阶段是不能获取到的,你需要UI界面渲染出现之后才能获取Image填满整列空间时的大小。
Best Regards
Yong Lu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.