Resizing a cell in a Silverlight datagrid column?

I was able to figure out how to expand and contract a datagrid column using the mouse. But after collapsing and expanding the column, the cell height does not decrease.

How can I take the original height of a cell (or row)? Can you take a look at this?

Thanks AJ

+2


a source to share


1 answer


Since I can't seem to find this solution on SO I'll be typing here.

You need to find the EVENT which is causing your string to be the wrong size. In my case, it's just scrolling up and down (but I've seen this on several different types of events). Here is the code to resize the datagrid:

    /// <summary>
    /// Reset datagrid row height
    /// </summary>
    /// <param name="row"></param>
    public void ResetRowHeight(DataGrid grid, DataGridRow row)
    {
        // only for autosize rows
        if (!double.IsNaN(row.Height)) return;

        // store current rowheight
        double rowheight = grid.RowHeight;

        // fore recalculating row height
        grid.RowHeight = 0;
        row.UpdateLayout();

        // restore rowheight
        grid.RowHeight = rowheight;
        row.UpdateLayout();
    }

      



Where grid is your datagrid and row is the row that needs to be reset.

Now, just find the event that is causing your problem and it should be.

0


a source







All Articles