如何在 Silverlight 4 中设置数据网格的高度
我在一个页面中有几个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
德里克·贝蒂的评论是正确的。
如果您的
Grid
位于StackPanel
内,并且StackPanel
没有HorizontalAlignment="Stretch"
(即在方向不增长),那么堆栈面板将适合其子面板。这会使
Grid
中的HorizontalAlignment="Stretch"
失效,因为它只能拉伸到其直接父级(StackPanel
)。事实上,它是一个StackPanel
意味着VerticalAlignment="Stretch"
对内部网格不执行任何操作。如果您确实需要内部
StackPanel
(只有一个子项是没有意义的),那么也向其中添加HorizontalAlignment="Stretch"
。这不会对垂直拉伸产生任何影响。就我个人而言,我只会转储围绕内部 Grid 的 StackPanel,因为它没有添加任何值。
Derek Beattie is correct in his comment.
If your
Grid
is within aStackPanel
and theStackPanel
does not haveHorizontalAlignment="Stretch"
(i.e. in the direction that does not grow) then the stack panel will fit its children.This voids the
HorizontalAlignment="Stretch"
in yourGrid
as it can only stretch to its immediate parent (theStackPanel
). The fact that it is aStackPanel
means thatVerticalAlignment="Stretch"
does nothing on the inner Grid.If you actually require the inner
StackPanel
(no point with only one child), then addHorizontalAlignment="Stretch"
to it as well. That will not do anything to the vertical stretch.Personally I would just dump the
StackPanel
that surrounds the innerGrid
as it add no value.