tags:

views:

1702

answers:

2

Hi all..

Been checking the web and this site, but couldn't come up with any descent results.

Is there a way to make a canvas in WPF show scrollbars on overflow ? Been trying the scrollviewer, but can't get it to work :(

Thanks in advance..

+3  A: 

The problem you're running into is that Canvas, unlike many WPF panels and containers, does not size to contents. That means if you add an element which goes outside the canvas boundaries it will not update it's size. Hence embedding a Canvas in a ScrollViewer will do no good unless you manually update the size of the Canvas.

It sounds like what you want is a Canvas which supports size to contents. This blog entry has exactly that control.

http://themechanicalbride.blogspot.com/2008/11/auto-sizing-canvas-for-silverlight-and.html

JaredPar
That's the info I've been looking for! Thanks a lot :)
cwap
A: 

I took a different approach and abandoned the Canvas for Grid. The Canvas is more performant but for my purposes at least I haven't noticed a difference. The grid can mimic the behavior of canvas by doing the following.

Create a single row,single column grid. Set the HorizontalAlignment to Left Set the VerticalAlignment to Top Use Margin "x,y,0,0" to set the position.

Bam..works just like canvas and it works great in a Scrollviewer.

logan