abelenky
abelenky

Reputation: 64672

Size of a Canvas in WPF

In a C# WPF application, I have a section:

<Canvas>
    <Image Source="myverybigimage.tif"/>
</Canvas>

In the code, I try to get the size of the Canvas, and expect it to be about 5000px wide, due to the big image it contains.

However, I've looked at the Canvas properties:

ActualWidth:  (just the size of the Window, around 1000)
RenderSize.Width: (also the size of the Window, around 1000)            
Width: NaN
MaxWidth: Infinity
MinWidth: Zero

Given a Canvas that contains an element larger than the window, is there a way to get the full size that the Canvas should / would be if it were fully drawn?

Upvotes: 2

Views: 2539

Answers (1)

AndrewS
AndrewS

Reputation: 6094

You can use the VisualTreeHelper.GetDescendantBounds.

Upvotes: 2

Related Questions