Silverlight 4 - ScrollViewer 和子 DataGrid MinHeight

发布于 2024-11-08 06:27:22 字数 1330 浏览 6 评论 0原文

编辑:我正在重写几乎整个问题,因为我意识到这个问题不正确且令人困惑。我对此表示歉意,但这个问题的假设不正确,导致无法回答。我最初试图简化它以使其更容易理解,但这使得无法复制我的问题。

如果我在 ScrollViewer 中有一个带有 MinHeightDataGrid,我希望随着我的 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 页面上有嵌套滚动条(我觉得这很令人反感,但它不在我的控制范围内)。这个想法是,顶级滚动条是某种“最后的手段”。

edit: I'm rewriting almost the entire question because I realized the question was incorrect and confusing. I apologize for this, but the question had incorrect assumptions that made it impossible to answer. I originally tried to simplify it to make it easier to understand, but this made it impossible to replicate my problem.

If I have an DataGrid with a MinHeight in a ScrollViewer, I would expect that as my ViewPort shrinks, the ActualHeight of the element would be decreased until it hits MinHeight before the scrollbars show up.

Instead, it seems that when the datagrid's rows cumulative heights add up to more than the MinHeight, this value overrides MinHeight

Is there a way to do this without manually sizing everything and having a ton of code?

Example:

<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>

If you were to populate this grid with some rows, if you maximize the window, the grid takes up most of the space and has white space after the rows. If you shrink it down, the layout takes away from the white space until that space runs out, then the root level ScrollViewer kicks in, even though MinHeight has not been reached.

If you replace the DataGrid with another rectangle, the behavior is different (obviously). The new rectangle would shrink down to height 20.

How do I achieve this with the grid? My requirements are to have nested scrollbars on my SL page (which I find distasteful, but it's not in my control). The idea is that the top level scrollbars are a "last resort" of sorts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

知你几分 2024-11-15 06:27:22

这个怎么样:

<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 值。

What about this:

<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>

You did not have the Grid.Row values set on either of the rectangles.

开始看清了 2024-11-15 06:27:22

您没有提供足够的信息来解决您的具体问题。然而,很容易证明 ScrollViewer 确实按照您想要的方式工作,只需将其简化为以下简单内容:

<UserControl ...>
    <ScrollViewer VerticalScrollBarVisibility="Auto">
        <Border MinHeight="200" BorderBrush="Blue" BorderThickness="1" Background="Red"/>
    </ScrollViewer>
</UserControl>

将其放入主页中的独立 Silverlight 应用程序中,您将看到当窗口足够小时,ScrollViewer 仅显示垂直滚动条。您可以在此处下载解决方案。

You've not provided sufficient information to solve your specific problem. However, it is easy to demonstrate that the ScrollViewer does work in exactly the fashion you desire by distilling down to something as simple as:

<UserControl ...>
    <ScrollViewer VerticalScrollBarVisibility="Auto">
        <Border MinHeight="200" BorderBrush="Blue" BorderThickness="1" Background="Red"/>
    </ScrollViewer>
</UserControl>

Put this in a standalone Silverlight application in the main page and you'll see that the ScrollViewer only displays the vertical scroll bar when the window is small enough. You can download the solution here.

吃素的狼 2024-11-15 06:27:22

这是因为 ScrollViewer 本身有一个边框和填充,占用的空间很小。尝试考虑一点额外的高度,使其与滚动条边框的空间相匹配。

另一种选择是更改滚动查看器的控制模板并删除内容呈现器周围占用的边框和额外空间。并将水平滚动可见性设置为折叠,这样它就不会占用空间。

This is because ScrollViewer itself has a border and padding that occupies little space of its own. Try considering little extra height that should match space of scrollbar border.

Another option will be to change the control template of scrollviewer and remove the border and extra space occupied around content presenter. And set horizontal scroll visibility to collapsed so it will not occupy space.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文