开发者

RowDetailsTemplate doesn't autosize back - Silverlight DataGrid

Please look at the attached screenshots.

I'm adding a datagrid to the rowdetails area for each row in the template.

The problem I have now is that the rowdetails area sizes correctly when it gets larger, ie when more content is added.

But once you collapse those rows(and their corresponding rowdetails) and open another rowdetail that is smaller than the first one, the rowdetails开发者_Python百科 container does not resize back(ie smaller) to fit the smaller content.

Please refer to the following flickr set, as I am not allowed to post images or more than one hyperlink: http://www.flickr.com/photos/47755109@N08/sets/72157623590404492/

How do I fix this issue?

Regards Renier


I searched the net about this issue, and found only very complicated workarounds (like here).

But it is actually VERY easy to fix that issue:

<sdk:DataGrid.RowDetailsTemplate>
    <DataTemplate>
         <ContentControl **VerticalAlignment="Top"**
...

--> if the control inside the datatemplate has a verticalalignment of "Top" (vs. the default "Stretch") the rows shrink as expected.

Regards Johannes


I know that this question is extremely old, but I just stumbled across it after having encountered this problem previously. It is related to other problems like http://forums.silverlight.net/p/96989/279885.aspx

Basically the root is that the DataGrid control wants to avoid having its rows jittering in size. Because of virtualization when you scroll an element off (lets presume horizontal scrolling) the element is no longer rendered. So when Silverlight tries to determine the height of a row if the largest piece of the row is off the side (and therefor virtualized) then it can't really know how tall the row should be without rendering all of the off screen content. So in this case they made a compromise, they use the height of elements that are on the screen or the current height of the row, if the current height is larger than all the elements currently on the screen. This results in the behavior you're describing.

There are a few workarounds, one described in the link above is to turn off virtualization on the DataGrid, but this can have performance impact if there is a non-trivial amount of data in the DataGrid. The other one that I used was to set the DataGrid row height to 0, force a re-render and then set the row height back to its default or auto. This way I was able to force the rows to shrink back down.

Hope that helps someone who stumbles across this problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜