當我試圖讓寬度和我的畫布的高度都返回-1#.INDCanvas.Width和Canvas.height返回-1#.IND
Dim ControlWidth as double = MyCanvas.Width
Dim ControlHeight as double = MyCanvas.Height
當我試圖讓寬度和我的畫布的高度都返回-1#.INDCanvas.Width和Canvas.height返回-1#.IND
Dim ControlWidth as double = MyCanvas.Width
Dim ControlHeight as double = MyCanvas.Height
-1#.IND
是Double.NaN
,這意味着寬度和高度設置爲auto
。要以像素(/單位?)爲單位獲得尺寸,您應該使用ActualWidth
和ActualHeight
。
Dim ControlWidth As Double = MyCanvas.ActualWidth
Dim ControlHeight As Double = MyCanvas.ActualHeight
IND,而非INF,簡稱「不確定」。換句話說,Double.NaN。 –
@HansPassant:你說得對,我的錯。謝謝! –
如果您想要元素的大小,請使用ActualWidth&ActualHeight。寬度和高度是用戶設置的屬性 – nkoniishvt