向 WPF Grid 添加垂直滚动条
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22756920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add a vertical scrollbar to WPF Grid
提问by Timon de Groot
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:
我有点卡在我的 WPF 网格的 ScrollViewer 上。我使用代码向 Grid 添加元素,因此 XAML 中的 Grid 主体是空的。我还通过代码添加了 ColumnDefinitions 和 RowDefinitions。这是我的网格的主体:
<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?
我必须在哪里添加 ScrollViewer 以及它应该具有哪些属性?
回答by Sajeetharan
You should embed the Grid Inside the ScrollViewer with the properties VerticalScrollBarVisibility and HorizontalScrollBarVisibility set to Auto
您应该将 Grid 嵌入到 ScrollViewer 中,并将 VerticalScrollBarVisibility 和 HorizontalScrollBarVisibility 属性设置为 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>

