如何在 Silverlight 4 中设置数据网格的高度

发布于 2024-12-06 18:04:27 字数 1947 浏览 0 评论 0原文

我在一个页面中有几个 DataGrid,每个 DataGrid 都通过以下布局/标记定位:

<border BorderBrush="Black">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <TextBlock x:Name="Title" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="6,0,0,0" Content="Panel Title"/>
        <toolkit:BusyIndicator Grid.Row="1" Grid.Column="0" x:Name="GridLoadingIndicator">
            <StackPanel Orientation="Vertical">
                <sdk:DataGrid x:name="GVData" 
                    VerticalAlignment="Stretch"
                    HorizontalAlignment="Stretch"
                    AutoGenerateColumns="False"
                    HorizontalScrollBarVisibility="Visible"
                    SelectionMode="Single">
                    <datagrid:DataGridTextColumn Header="Column 1" Binding="{Binding Col1}" />                              
                    <datagrid:DataGridTextColumn Header="Column 2" Binding="{Binding Col2}" />                              
                    <datagrid:DataGridTextColumn Header="Column 3" Binding="{Binding Col3}" />                              
                    <datagrid:DataGridTextColumn Header="Column 4" Binding="{Binding Col4}" />                              
                    <datagrid:DataGridTextColumn Header="Column 5" Binding="{Binding Col5}" />
                </sdk:DataGrid>
            </StackPanel>
        </toolkit:BusyIndicator>
        <StackPanel x:Name="PagerControls" Grid.Row="2" Grid.Column="0" Orientation="Horizontal">
            <!-- Pager -->
        </StackPanel>
    </Grid>
</border>

嗯,问题是网格本身不想拉伸以填充为其分配的空间,更重要的是它不想拉伸也不响应页面大小事件。

关于如何解决这个问题有什么想法吗?

I have a couple of DataGrids inside a page and each DataGrid is positioned via the following layout/markup:

<border BorderBrush="Black">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <TextBlock x:Name="Title" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="6,0,0,0" Content="Panel Title"/>
        <toolkit:BusyIndicator Grid.Row="1" Grid.Column="0" x:Name="GridLoadingIndicator">
            <StackPanel Orientation="Vertical">
                <sdk:DataGrid x:name="GVData" 
                    VerticalAlignment="Stretch"
                    HorizontalAlignment="Stretch"
                    AutoGenerateColumns="False"
                    HorizontalScrollBarVisibility="Visible"
                    SelectionMode="Single">
                    <datagrid:DataGridTextColumn Header="Column 1" Binding="{Binding Col1}" />                              
                    <datagrid:DataGridTextColumn Header="Column 2" Binding="{Binding Col2}" />                              
                    <datagrid:DataGridTextColumn Header="Column 3" Binding="{Binding Col3}" />                              
                    <datagrid:DataGridTextColumn Header="Column 4" Binding="{Binding Col4}" />                              
                    <datagrid:DataGridTextColumn Header="Column 5" Binding="{Binding Col5}" />
                </sdk:DataGrid>
            </StackPanel>
        </toolkit:BusyIndicator>
        <StackPanel x:Name="PagerControls" Grid.Row="2" Grid.Column="0" Orientation="Horizontal">
            <!-- Pager -->
        </StackPanel>
    </Grid>
</border>

Well, the problem is that the grid itself doesn't want to stretch to fill the space allotted for it, and more over it doesn't respond to page size events either.

Any ideas on how to fix the issue?

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

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

发布评论

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

评论(1

以歌曲疗慰 2024-12-13 18:04:27

德里克·贝蒂的评论是正确的。

如果您的Grid位于StackPanel内,并且StackPanel没有Horizo​​ntalAlignment="Stretch"(即在方向不增长),那么堆栈面板将适合其子面板。

这会使 Grid 中的 Horizo​​ntalAlignment="Stretch" 失效,因为它只能拉伸到其直接父级(StackPanel)。事实上,它是一个 StackPanel 意味着 VerticalAlignment="Stretch" 对内部网格不执行任何操作。

如果您确实需要内部 StackPanel (只有一个子项是没有意义的),那么也向其中添加 Horizo​​ntalAlignment="Stretch" 。这不会对垂直拉伸产生任何影响。

就我个人而言,我只会转储围绕内部 Grid 的 StackPanel,因为它没有添加任何值。

Derek Beattie is correct in his comment.

If your Grid is within a StackPanel and the StackPanel does not have HorizontalAlignment="Stretch" (i.e. in the direction that does not grow) then the stack panel will fit its children.

This voids the HorizontalAlignment="Stretch" in your Grid as it can only stretch to its immediate parent (the StackPanel). The fact that it is a StackPanel means that VerticalAlignment="Stretch" does nothing on the inner Grid.

If you actually require the inner StackPanel (no point with only one child), then add HorizontalAlignment="Stretch" to it as well. That will not do anything to the vertical stretch.

Personally I would just dump the StackPanel that surrounds the inner Grid as it add no value.

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