user2330678
user2330678

Reputation: 2311

How can I enable scrollbars on the WPF Grid?

How can I enable scrollbars on WPF Grid? The grid is inside a stack panel.

Upvotes: 1

Views: 76

Answers (2)

TMan
TMan

Reputation: 4122

I could be wrong but I don't think Grid has a scroll viwer built in. You could do something like:

 <ScrollViewer>
    <StackPanel>
      <Grid />
    </StackPanel>
 </ScrollViewer>

Note: Be aware that Stackpanels content generally will not vertically stretch the way you would expect

Upvotes: 2

McGarnagle
McGarnagle

Reputation: 102793

Edit I assumed that the OP meant DataGrid ... if Grid was intended, then I will defer to @TMan's answer ...


The characteristic of a StackPanel is that it presents an infinite (vertical or horizontal) dimension. So if the DataGrid is its child, then it will see it has infinite space, and use up the full amount it needs (hence no scroll).

To enable scrolling, you will need to limit the DataGrid's height somehow. For example set a Height or MaxHeight on the grid. Or use another panel like Grid that doesn't present infinite space.

You could also consider wrapping the StackPanel itself in a ScrollViewer.

Upvotes: 1

Related Questions