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.
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 event ScrollViewer.ScrollChanged
.
Xaml
<DataGrid x:Name="dtGrid"
ScrollViewer.ScrollChanged="dtGrid_ScrollChanged"
... />
Code behind
private void dtGrid_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
if (e.HorizontalChange != 0)
{
// Do stuff..
}
}
If by 'drags horizontally' you mean 'scrolls horizontally' then you can use the ScrollViewer.ScrollChanged
event. The ScrollChangedEventArgs
contain properties such as HorizontalOffset
and HorizontalChange
.
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