George
George

Reputation: 211

How to Prevent an Autoscroll in DataGrid

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?

Upvotes: 0

Views: 1101

Answers (2)

Waqar Mumtaz
Waqar Mumtaz

Reputation: 1

I have achieved the same, which you wanted with the following code snippet. Set DataGrid attribute in Xaml ScrollViewer.CanContentScroll="False"

    <DataGrid ScrollViewer.CanContentScroll="False" ... />

Upvotes: 0

George
George

Reputation: 211

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.

Upvotes: 1

Related Questions