向 DataGrid 添加滚动事件
我有一个 DataGrid 定义如下,作为 UserControl 的一部分:
<DataGrid x:Name="dtGrid" AutoGenerateColumns="False"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode ="Standard"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
ScrollViewer.IsDeferredScrollingEnabled="True"
CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="True"
ItemsSource ="{Binding}" Block.TextAlignment="Center"
AlternatingRowBackground="#F1F1F1" RowBackground="White"
CanUserAddRows="False" CanUserDeleteRows="False" FrozenColumnCount="1"
GridLinesVisibility="None" >
</DataGrid>
我想添加一个事件,当用户在 DataGrid 上水平拖动时,它会更新我拥有的另一个图表。有人可以指出我开始做这件事的方向吗?谢谢。
I have a DataGrid defined as follows as part of a UserControl:
<DataGrid x:Name="dtGrid" AutoGenerateColumns="False"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode ="Standard"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
ScrollViewer.IsDeferredScrollingEnabled="True"
CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="True"
ItemsSource ="{Binding}" Block.TextAlignment="Center"
AlternatingRowBackground="#F1F1F1" RowBackground="White"
CanUserAddRows="False" CanUserDeleteRows="False" FrozenColumnCount="1"
GridLinesVisibility="None" >
</DataGrid>
I'd like to add an event on when the user drags horizontally on the DataGrid, it updates another chart I have. Can someone point me in the direction to get this started? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解你的问题,你想知道用户何时水平滚动
DataGrid
。这可以通过附加事件ScrollViewer.ScrollChanged
来完成。Xaml
代码背后
If I understand your question correctly you want to find out when the user has scrolled the
DataGrid
Horizontally. This can be done with the attached eventScrollViewer.ScrollChanged
.Xaml
Code behind
如果“水平拖动”指的是“水平滚动”,那么您可以使用
ScrollViewer.ScrollChanged
事件。ScrollChangedEventArgs
包含HorizontalOffset
和HorizontalChange
等属性。If by 'drags horizontally' you mean 'scrolls horizontally' then you can use the
ScrollViewer.ScrollChanged
event. TheScrollChangedEventArgs
contain properties such asHorizontalOffset
andHorizontalChange
.