Search code examples
c#wpfxamldata-bindingscrollviewer

WPF ScrollBar not showing up on Grid


Here is my Grid, no matter what I tried I can't get the VerticalScrollBar to show up.

<Grid>
  <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" Style="{StaticResource MaterialDesignScrollViewer}">
     <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
     </Grid>
   </ScrollViewer>
</Grid>

I need the Grid to be Stretched both Horizontally and Vertically so that it can dynamically resize itself. I even tried setting the Height as Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=ActualHeight}" for both the Grid and ScrollViewer.


Solution

  • Don't enclose scroll viewer inside another grid.

     <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" Style="{StaticResource MaterialDesignScrollViewer}">
         <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
         </Grid>
       </ScrollViewer>