I am trying to load an image within a canvas such that, if the size of image overflows the canvas, the scroll bars should get activated (MS Paint style)
<Window>
<ScrollViewer>
<Canvas ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible">
<Image Source="SampleImage.jpg" />
</Canvas>
</ScrollViewer>
</Window>
- Now as
Canvas
is stretched toWindow
's size, scroll-bars won't appear asCanvas
is not actually overflowing out of theWindow
. - Secondly, as the
Image
is much bigger than theCanvas
, it is getting clipped at the bounds ofCanvas
, soScrollViewer
doesn't think that its content:Canvas
is actually overflowing.
It happens a lot of time with StackPanel
s too, that even though the bound data has tens of rows, but still the scrollbars don't get activated. Sometimes scrollviewers appear as mystery to me.
So, what should be the basic logic kept in mind when using ScrollViewer
control.
Thank you.
Edit: Just edited the question title, so that whosoever has problem with canvas can get this question easily in search.