cwap
cwap

Reputation: 11277

Is there a way to automagically make a canvas scroll on overflow in WPF?

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..

Upvotes: 2

Views: 7972

Answers (2)

logan
logan

Reputation: 25

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.

Upvotes: 0

JaredPar
JaredPar

Reputation: 754665

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

Upvotes: 3

Related Questions