开发者

Resizing Cell Height of Silverlight datagrid row?

I was able to figure out how to expand and contract a column of datagrid using mouse. But after contracting and expanding a column, the height of cell doesn’t开发者_Go百科 decrease.

How can I bring the original height of cell (or row)? Can you look into this?

Thanks AJ


Since I'm unable to find this solution on SO, I'll type mine in here.

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

    /// <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 resetting.

Now just find the event that's causing your problem and that should be it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜