向 WPF Grid 添加垂直滚动条 [英] Add a vertical scrollbar to WPF Grid

查看:388
本文介绍了向 WPF Grid 添加垂直滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点卡在我的 WPF 网格的 ScrollViewer 上.我使用代码向 Grid 添加元素,因此 XAML 中的 Grid 主体是空的.我还通过代码添加了 ColumnDefinitions 和 RowDefinitions.这是我的网格的主体:

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>

我必须在哪里添加 ScrollViewer 以及它应该具有哪些属性?

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

推荐答案

您应该将 Grid 嵌入到 ScrollViewer 中,并将 VerticalScrollBarVisibility 和 Horizo​​ntalScrollBarVisibility 属性设置为 Auto

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>

这篇关于向 WPF Grid 添加垂直滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆