我怎么针在Silverlight下面另外一个控制? [英] How do I pin one control below another in Silverlight?

查看:185
本文介绍了我怎么针在Silverlight下面另外一个控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用的DataGrid 与自定义模板,这样我可以添加一个特殊的行数据行底部的项目。我想这个特殊行到最后一行下固定,但不作为一部分的ScrollViewer ,这样,它仍然是最后一排压住,直到特行的底部命中数据网格的底部,那么我想行区域的大小在其间的空间,并相应地滚动,用特殊行始终可见。

I have a project that uses a DataGrid with a custom template so that I can add a special row to the bottom of the data rows. I would like this special row to be pinned under the last row but not as part of the ScrollViewer, such that it remains pinned under the last row until the bottom of the special row hits the bottom of the data grid, then I would like the rows region to size to the space inbetween and scroll accordingly, with the special row always visible.

到目前为止,我有我的特殊行作为的ScrollViewer RowsPresenter 沿的一部分。无论是演示者和特殊行是在自动调整大小行的电网的ScrollViewer ,用的ScrollViewer 在星大小的网格行,这样,当它运行的空间滚动条将出现。如何从如此,其中的行和特殊行滚动在一起,我想去的地方是,其中的行滚动,但特殊行是在底部,总是可见的?

So far, I have my special row as part of the ScrollViewer along with the RowsPresenter. Both the presenter and the special row are in auto-sized rows of a Grid within the ScrollViewer, with the ScrollViewer in a star-sized grid row so that the scrollbar will appear when it runs out of space. How do I get from this, where the rows and special row scroll together to where I want to be, where the rows scroll, but the special row is pinned at the bottom and always visible?

虽然我的例子中使用的DataGrid ,我相信这可以简化到不同高度的只是一个滚动的元素,并固定其下的控制。到目前为止,我想我需要一个画布而非电网主办我的的ScrollViewer 和同伴特殊行,有一些逻辑来调整高度和位置时,的ScrollViewer 增长(如果我能检测到),但我还没有尝试这个。有没有更好的办法或者说是画布接近最好的一个?

Although my example uses a DataGrid, I am sure this can be simplified down to just a scrollable element of varying height, and a control pinned beneath it. So far, I imagine I need a Canvas rather than a Grid to host my ScrollViewer and companion special row, with some logic to adjust heights and positions when the ScrollViewer grows (if I can detect that), but I haven't yet tried this. Is there a better way or is the Canvas approach the best one available?

推荐答案

我能够通过使用来解决这个问题的电网有两个自动调整大小的行;一排为的DataGrid 和我的固定行的行。然后,我监视电网的大小,一经调整,请查看​​是否在电网的的ActualHeight较大比屏幕房地产它被赋予占领。如果是,我改变了的DataGrid 的排明星般大小,这导致了固定行中泛起寄托于母公司控制的底部和的DataGrid 显示其行的滚​​动条。我改变行回自动调整大小时,提供更大的空间。

I was able to solve this by using a Grid with two auto-sized rows; a row for the DataGrid and a row for my pinned row. I then monitor the sizing of the Grid and, upon resizing, look to see if the Grid's ActualHeight is greater than the screen real-estate it is given to occupy. If it is, I change the DataGrid's row to star-sized, which results in the pinned row appearing pinned to the bottom of the parent control and the DataGrid displaying a scrollbar for its rows. I change the row back to auto-sizing when more space is made available.

这显然对于任何方案,其中一行必须始终在屏幕上工作,但也必须是,固定到另一个底部

This would obviously work for any scenario where one row must always be on screen but must also be pinned to the bottom of another.

钉扎的代码看起来是这样的:

The pinning code looks something like this:

RowDefinition row = this.mainGrid.RowDefinitions[0];
if (row.Height.GridUnitType == GridUnitType.Auto)
{
    if (this.mainGrid.ActualHeight > this.ActualHeight)
    {
        row.Height = new GridLength(1, GridUnitType.Star);
    }
}
else
{
    if (this.dataGrid.DesiredSize.Height < row.ActualHeight)
    {
        row.Height = GridLength.Auto;
    }
}

这篇关于我怎么针在Silverlight下面另外一个控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆