12

I have done VerticalScrollBarVisibility="Disabled" because i dont want the content inside datagrid to be viewed which crosses the assigned height. I am not able to see scroll bar after giving the above statement.but i still can scroll down and see the rows.Can someone tell me how do i disable scrolling all together? Thanks

5 Answers 5

7

Once you've disabled the VerticalScrollBarVisibility for your DatGrid, you need to disable the ScrollViewer's scroll functionality like this:

ScrollViewer.CanContentScroll="False"

But when you do his make sure that you have already defined a standard height for your entire DataGrid and your DataGrid rows such that the user can see all the rows you want them to see, otherwise the chopped off rows will not be displayed and the user can not scroll down to see them.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

7

The correct approach would be to disable the Hit target

DataGrid.IsHitTestVisible = false;

2 Comments

This works, but doesn't solve the problem if you're hoping to actually be able to click within the data grid (just to ignore the mouse scroll inside it)
It also disables clicking on the rows
3

Allow DataGrid to show all it's content (so it needn't scroll bar):

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <DataGrid x:Name="DataGrid" />
</Grid>

You can than put the result in any place. It'll cut down it's size to the owner's dimensions

1 Comment

this does not solve the problem, especially if the data grid has many rows
2

The accepted solution did not work for me since I needed row selection. I solved all my issues by disabling datagrid panning (for mouse dragging) and handling key down events (for keyboard). In datagrid XAML:

ScrollViewer.PanningMode="None"

And:

PreviewKeyDown="OnDatagridPreviewKeyDown"

In code behind:

private void OnDatagridPreviewKeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Right || e.Key == Key.Left)
        e.Handled = true;
}

HTH.

Edit: My answer applies to columns but everything is similar for rows.

Comments

0

Just wanted to add an answer that applied to columns. On occasion, you may find that the Datagrid will scroll to extra columns that you would prefer remain invisible, especially if the height is specifically adjusted so that any additional columns are invisible. I simply attached a Loaded handler to the Datagrid and set all of the additional columns to a width of 0 and made them hidden.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.