设置为自动时如何获取控制器的高度/宽度 [英] How to get Height/Width of a controller when it is set to be Auto

查看:135
本文介绍了设置为自动时如何获取控制器的高度/宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我在网格中有一个画布",画布的高度"和宽度"设置为自动".
在后面的代码中,我需要在此Canvas中绘制一个形状(即Line,Rectangle),并将形状的大小设置为Canvas的大小(即,Rectangle与画布的高度相同,宽度为画布的一半).画布宽度)
我使用了以下内容:

Hey guys,
I have a Canvas inside a grid, the Height and Width of the canvas is set to be Auto.
In my code behind, I need to draw a shape (i.e. Line, Rectangle) inside this Canvas and set the size of the shape to the size of Canvas (i.e. a Rectangle which has a Height same as the canvas and a width half of the canvas width)
I used the following :

double H = A_Canvas.Height;
double H = A_Canvas.ActualHeight;




对于第一个,我得到NaN,对于第二个,我得到0.




For the first one, I get NaN and for the second one I get 0.

How should I do this ?!

推荐答案

这取决于您尝试查找画布高度的位置.
您可以在包含的视图中覆盖OnRenderSizeChanged.此时,已经为画布指定了大小和ActualHeight,然后可以正常工作.
It depends on where you are trying to find out your canvas height.
You could override the OnRenderSizeChanged in the containing view. At this point the canvas has been given a size and ActualHeight with then work correctly.


这篇关于设置为自动时如何获取控制器的高度/宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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