Timon de Groot
Timon de Groot

Reputation: 8153

Add a vertical scrollbar to WPF Grid

I'm kinda stuck on the ScrollViewer of my WPF Grid. I add elements to the Grid using code, so the Grid body in XAML is just empty. I also add ColumnDefinitions and RowDefinitions by code. This is the body of my Grid:

<Grid x:Name="grdChampions" HorizontalAlignment="Left" Height="336" Margin="65,60,0,0" VerticalAlignment="Top" Width="671">

</Grid>

Where do I have to add the ScrollViewer and what properties should it have?

Upvotes: 23

Views: 42105

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222522

You should embed the Grid Inside the ScrollViewer with the properties VerticalScrollBarVisibility and HorizontalScrollBarVisibility set to Auto

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
    <Grid x:Name="grdChampions" HorizontalAlignment="Left" Height="336" Margin="65,60,0,0" VerticalAlignment="Top" Width="671">
    </Grid>
</ScrollViewer>

Upvotes: 58

Related Questions