Reputation: 505
I have a class that extends a Canvas
. On creation I explicitly set its width to a value:
Public Sub New(w As Integer, h As Integer)
Me.Width = w
Me.Height = h
End Sub
Now I add instances of this to a canvas to another canvas using cnvPreview.Children.Add(e)
where e
is the instance of my extended canvas.
However when I run the application, the ActualWidth
and ActualHeight
of these canvases are 0.
How can this be fixed?
Upvotes: 0
Views: 1954
Reputation: 180
Note that ActualHeight
and ActualWidth
will give you the values after rendering the control. Suppose if the Canvas
Height
and Width
is 50 and after rendering the Canvas
is shrinked then it will return a lower ActualHeight
and ActualWidth
value or maybe zero if not visible.
Upvotes: 0
Reputation: 4161
Don't Canvas's
shrink to the smallest size possible, yet still display fully their own children? Might this be causing the ActualHeight
and ActualWidth
values to be zero. Try adding say, a TextBlock
and reading the values then.
I believe that this is explained better on this other post: Why are ActualWidth and ActualHeight 0.0 in this case?
Upvotes: 1