0

I am working on implementing the re-sizing feature in WPF DataGrid, it supports re-sizing through column/row headers but what I want is to allow re-sizing on grid lines.

So, user can re-size rows/columns from anywhere in DataGrid. I have been able to implement the functionality and it works fine for columns but in case of rows its messed up.

You can re-size a row through header and you can also re-size through any cell of that row but problem occurs if you use them together i.e once you have re sized a row through a cell, re-sizing through row header would stop working(shows weird behavior). Here is how it looks like (notice the broken grid lines...) -

enter image description here

I have created a sample to reproduce this behavior -

WPF Toolkit DataGrid Sample - Adding GridLines Resizing

To reproduce the problem

  1. Re-size a row through grid-lines(any cell) and then

  2. Re-size the same row through row header.

will appreciate any kind of help.

Thanks

1 Answer 1

0

I solved the problem by setting the height of CellPresenter instead of Row. Here is the main code block -

double newHeight = cellsPresenter.ActualHeight + e.VerticalChange;     
DataGridRowHeader rowHeader = GetFirstVisualChild<DataGridRowHeader>(row);    
if (rowHeader != null)    
{ 
    // clamp the CellsPresenter size to the MaxHeight of Row, 
    // because row wouldn't grow any larger
    double maxHeight = row.MaxHeight;
    if (newHeight > maxHeight)
    {
        newHeight = maxHeight;
    }
}

cellsPresenter.Height = newHeight;

// Updating row's height doesn't work correctly; shows weird behavior    
// row.Height = newHeight >= 0 ? newHeight : 0;

I have blogged about this in detail here -

WPF DataGrid Customization: Resizing Row/Column through DataGridCell gridlines

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.