Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of a Canvas in WPF

Tags:

c#

canvas

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?

like image 902
abelenky Avatar asked Nov 28 '25 06:11

abelenky


1 Answers

You can use the VisualTreeHelper.GetDescendantBounds.

like image 146
AndrewS Avatar answered Nov 29 '25 20:11

AndrewS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!