如何防止 DataGrid 中的自动滚动
我在 XAML 中定义了一个数据网格,如下所示:
<toolkit:DataGrid Margin="10,116,62,34" Name="WADataGrid" RowBackground="LightYellow" AlternatingRowBackground="White"
BorderBrush="Gray" BorderThickness="2" IsReadOnly="True" CanUserReorderColumns="False" CanUserResizeColumns="True"
CanUserSortColumns = "True" SelectionMode="Extended" MouseDoubleClick="DataGrid_MouseDoubleClick"
AutoGenerateColumns="False" Height="400" Canvas.Left="0" Canvas.Top="-76" Width="731">
然后,我处理双击发生的行所选择的项目。
但是,当垂直滚动条打开并且网格最后一行下方还有尚未显示的项目时,会发生什么情况,双击会导致最后一行向上滚动,使其成为倒数第二行。双击方法中所选项目的值是被隐藏并向上滚动的行。
当双击显示的最后一行时,如何防止数据网格向上滚动?
I have a datagrid defined in XAML as follows:
<toolkit:DataGrid Margin="10,116,62,34" Name="WADataGrid" RowBackground="LightYellow" AlternatingRowBackground="White"
BorderBrush="Gray" BorderThickness="2" IsReadOnly="True" CanUserReorderColumns="False" CanUserResizeColumns="True"
CanUserSortColumns = "True" SelectionMode="Extended" MouseDoubleClick="DataGrid_MouseDoubleClick"
AutoGenerateColumns="False" Height="400" Canvas.Left="0" Canvas.Top="-76" Width="731">
I then process the item selected by the row that the double click occurred.
What happens though when the vertical scrollbar is on and there are items below the last row of the grid not yet displayed, the double click causes the last row to scroll up one so that it becomes the next to last row. The value of the selected item in the double click method is the row that had been hidden and got scrolled up.
How can I prevent the datagrid from scrolling up when the last row displayed is double clicked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以通过使用 PreviewMouseDoubleClick 来解决这个问题。
这样做时,我能够在滚动发生之前识别正确的行。
I was able to work around this by instead using PreviewMouseDoubleClick.
When doing that I was able to identify the correct row before the scroll occurred.
我已经通过以下代码片段实现了您想要的相同效果。在 Xaml 中设置 DataGrid 属性
ScrollViewer.CanContentScroll="False"
I have achieved the same, which you wanted with the following code snippet. Set DataGrid attribute in Xaml
ScrollViewer.CanContentScroll="False"