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?
In order to enable horizontal and/or vertical scrollbars you need to set the ScrollViewer's attached properties HorizontalScrollBarVisibility and/or VerticalScrollBarVisibility.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With