Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a vertical scrollbar to WPF Grid

Tags:

c#

wpf

xaml

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?

like image 589
Timon de Groot Avatar asked Mar 31 '14 08:03

Timon de Groot


People also ask

How do I add a vertical ScrollBar in WPF?

In order to enable horizontal and/or vertical scrollbars you need to set the ScrollViewer's attached properties HorizontalScrollBarVisibility and/or VerticalScrollBarVisibility.

How do I add a ScrollBar to XAML?

The <ScrollBar> element of XAML represents a scroll bar control in UI. The ScrollBar control is used to add horizontal and vertical scroll bars to content controls. This tutorial and code examples show how to use a ScrollBar control in a WPF app using XAML. The following code example creates a ScrollBar.


1 Answers

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>
like image 92
Sajeetharan Avatar answered Sep 26 '22 00:09

Sajeetharan