简体   繁体   English

RowDetailsTemplate不会自动调整大小-Silverlight DataGrid

[英]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. 我正在为模板中的每一行的rowdetails区域添加一个数据网格。

The problem I have now is that the rowdetails area sizes correctly when it gets larger, ie when more content is added. 我现在遇到的问题是,当行变大时,即当添加更多内容时,rowdetails区域大小正确。

But once you collapse those rows(and their corresponding rowdetails) and open another rowdetail that is smaller than the first one, the rowdetails container does not resize back(ie smaller) to fit the smaller content. 但是,一旦折叠了这些行(及其对应的rowdetails)并打开了另一个小于第一个行的rowdetail,rowdetails容器就不会调整大小(即变小)以适合较小的内容。

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/ 请参阅以下flickr集,因为不允许发布图像或多个超链接: 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 它与其他问题有关,例如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. 基本上,根本原因是DataGrid控件希望避免其行的大小发生抖动。 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. 因此,如果Silverlight尝试确定一行的最大高度(如果该行的最大部分不在侧面)(并因此进行了虚拟化),那么在不呈现所有屏幕外内容的情况下,它真的无法知道行的高度。 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. 有几种解决方法,上面链接中描述的一种方法是关闭DataGrid上的虚拟化,但是如果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. 我使用的另一个方法是将DataGrid行高设置为0,强制重新渲染,然后将行高设置回其默认值或自动值。 This way I was able to force the rows to shrink back down. 这样,我就可以迫使行缩小。

Hope that helps someone who stumbles across this problem. 希望对遇到这个问题的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Silverlight,XAML,DataGrid不会自动调整大小,没有自动滚动条 - Silverlight, XAML, DataGrid does not autosize, no auto scrollbars 如何使Silverlight DataGrid足够宽以显示整个RowDetailsTemplate - How to make Silverlight DataGrid wide enough to show entire RowDetailsTemplate silverlight RowDetailsTemplate是否存在未写入的限制? - Are there unwritten limitations of the silverlight RowDetailsTemplate? combobox selectionchanged事件不会在Silverlight mvvm中更新datagrid - combobox selectionchanged event doesn't update datagrid in Silverlight mvvm 自定义实体对象属性不会在Silverlight DataGrid中更新 - Custom Entity object property doesn't update in Silverlight DataGrid 在另一个Datagrid的RowDetailsTemplate中使用Datagrid - Using Datagrid within RowDetailsTemplate of another Datagrid Silverlight标签中的AutoSize功能 - AutoSize feature in a label in Silverlight silverlight:从RowDetailsVisibilityChanged设置RowDetailsTemplate控件 - silverlight: setting RowDetailsTemplate controls from RowDetailsVisibilityChanged Silverlight dataGrid 与 ria 服务的绑定不起作用 - Silverlight dataGrid binding with ria Service doesn' work Silverlight Scrollviewer鼠标滚轮仅在datagrid上滚动时滚动。 在datagrid外部滚动时页面不滚动 - Silverlight Scrollviewer Mousewheel scrolls only when scrolled on datagrid. Page doesn't scroll when scrolled outside the datagrid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM