Search code examples
c#.netwpfscrollvieweractualheight

Scrollviewer ActualHeight exceeds the screen resolution


I have a Grid with these rows settings: (I can't post much code, sorry)

RowDefinition Height="1*"

RowDefinition Height="120"

Inside that grid I have a ScrollViewer with Height="Auto" and verticalAlignment = "Stretch" at Row 0.

At row 2 I have another grid with a fix height of 60 pixels.

When I do this.UpdateLayout (inside an UserControl), then the scrollviewer.ActualHeight goes to 2332, which is the same size of an image inside it and exceed the resolution screen. Why its not updating to fit the screen?

Thanks.


Solution

  • If you place the outer Grid in f.i. a StackPanel with orientation vertical, then there might not be a limit on the height of the grid, and then not a vertical limit on the ScrollViewer. Place the Grid in a DockPanel, or set a (maximum) height of the Grid. Then the ScrollViewer will have a limited height.