编辑:我几乎重写了整个问题,因为我意识到这个问题不正确且令人困惑。我为此道歉,但问题的假设不正确,因此无法回答。我最初试图简化它以使其更容易理解,但这使得我的问题无法重现。
如果我在 ScrollViewer
中有一个带有 MinHeight
的 DataGrid
,我希望随着我的 ViewPort 缩小,ActualHeight元素的
将减小,直到它在滚动条出现之前达到 MinHeight
。
相反,似乎当数据网格的行累积高度加起来超过 MinHeight
时,此值会覆盖 MinHeight
有没有一种方法可以做到这一点,而无需手动调整所有内容的大小并编写大量代码?
例子:
<ScrollViewer VerticalScrollBarVisibility="Auto" Background="Red">
<Grid x:Name="LayoutRoot" Background="Black" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition MinHeight="20"/>
<RowDefinition Height="80"/>
</Grid.RowDefinitions>
<sdk:DataGrid AutoGenerateColumns="True" Name="dataGrid1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" MinHeight="20" />
<Rectangle Fill="Blue" Width="100" Height="80" Grid.Row="1" />
</Grid>
</ScrollViewer>
如果您要用一些行填充此网格,如果您最大化窗口,则网格会占据大部分空间并且在行之后有空白。如果将其缩小,布局会从空白处移走,直到该空间用完,然后根级别 ScrollViewer
启动,即使尚未达到 MinHeight
。
如果将 DataGrid
替换为另一个矩形,则行为会有所不同(很明显)。新的矩形会缩小到 20 的高度。
如何使用网格实现此目的?我的要求是在我的 SL 页面上有嵌套的滚动条(我觉得这很反感,但它不受我的控制)。这个想法是顶级滚动条是某种“最后的手段”。
最佳答案
这个怎么样:
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="250" />
</Grid.RowDefinitions>
<Rectangle MinHeight="150" Background="Red" Grid.Row="0" />
<Rectangle Height="250" Background="Blue" Grid.Row="1" />
</Grid>
您没有在任何一个矩形上设置 Grid.Row 值。
关于wpf - Silverlight 4 - ScrollViewer 和子 DataGrid MinHeight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6047740/