Silverlight DataGrid 无法拉伸以容纳数据源中的所有项目?
我在让 Silverlight DataGrid 拉伸以容纳其数据源中的所有项目时遇到问题。 我有一个包含两个 DataGrid 的网格。 我尝试在网格和数据网格上设置 height=Auto 。 我尝试在网格和数据网格上设置 HorizontalContentAlignment="Stretch"。 对象标签的 height="100%" 我已经在网格的 RowDefinitions 上设置了 Height="*"
任何帮助将不胜感激!
这是代码清单:
<UserControl x:Class="TimeSheet.SilverLight.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Height="Auto" ShowGridLines="True" HorizontalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<local:DataGrid BorderThickness="5" HorizontalContentAlignment="Stretch" AutoGenerateColumns="False" VerticalAlignment="Top" x:Name="NonProjectGrid" Grid.Row="0">
<local:DataGrid.Columns>
<local:DataGridTextColumn Header="Activity" Binding="{Binding TaskName}" />
<local:DataGridTextColumn Header="Monday" Binding="{Binding Monday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Tuesday" Binding="{Binding Tuesday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Wednesday" Binding="{Binding Wednesday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Thursday" Binding="{Binding Thursday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Friday" Binding="{Binding Friday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Saturday" Binding="{Binding Saturday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Sunday" Binding="{Binding Sunday, Mode=TwoWay}" />
</local:DataGrid.Columns>
</local:DataGrid>
<local:DataGrid BorderThickness="5" HorizontalContentAlignment="Stretch" AutoGenerateColumns="False" VerticalAlignment="Top" x:Name="ProjectGrid" Grid.Row="2">
<local:DataGrid.Columns>
<local:DataGridTextColumn Header="Bug Number" Binding="{Binding BugNo}" />
<local:DataGridTextColumn Header="Activity" Binding="{Binding TaskName}" />
<local:DataGridTextColumn Header="Monday" Binding="{Binding Monday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Tuesday" Binding="{Binding Tuesday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Wednesday" Binding="{Binding Wednesday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Thursday" Binding="{Binding Thursday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Friday" Binding="{Binding Friday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Saturday" Binding="{Binding Saturday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Sunday" Binding="{Binding Sunday, Mode=TwoWay}" />
</local:DataGrid.Columns>
</local:DataGrid>
<Button Name="AddBugBtn" Width="125" Height="25" Content="Add From Bugzilla" Click="AddBug_Click" Grid.Row="3" HorizontalAlignment="Right"></Button>
<Button Name="SaveBtn" Width="125" Height="25" Content="Save" Click="Save_Click" Grid.Row="3" HorizontalAlignment="Left"></Button>
</Grid>
I'm having problems getting a Silverlight DataGrid to stretch to accommodate all the items in it's dataSource.
I've got a Grid that contains two DataGrids.
I've tried setting height=Auto on the Grid and the DataGrids.
I've tried setting HorizontalContentAlignment="Stretch" on the Grid and the DataGrids.
The object tag has height="100%"
I've set the Height="*" on the RowDefinitions for the Grid
Any help would be very much appreciated!
Here's the code listing:
<UserControl x:Class="TimeSheet.SilverLight.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Height="Auto" ShowGridLines="True" HorizontalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<local:DataGrid BorderThickness="5" HorizontalContentAlignment="Stretch" AutoGenerateColumns="False" VerticalAlignment="Top" x:Name="NonProjectGrid" Grid.Row="0">
<local:DataGrid.Columns>
<local:DataGridTextColumn Header="Activity" Binding="{Binding TaskName}" />
<local:DataGridTextColumn Header="Monday" Binding="{Binding Monday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Tuesday" Binding="{Binding Tuesday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Wednesday" Binding="{Binding Wednesday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Thursday" Binding="{Binding Thursday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Friday" Binding="{Binding Friday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Saturday" Binding="{Binding Saturday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Sunday" Binding="{Binding Sunday, Mode=TwoWay}" />
</local:DataGrid.Columns>
</local:DataGrid>
<local:DataGrid BorderThickness="5" HorizontalContentAlignment="Stretch" AutoGenerateColumns="False" VerticalAlignment="Top" x:Name="ProjectGrid" Grid.Row="2">
<local:DataGrid.Columns>
<local:DataGridTextColumn Header="Bug Number" Binding="{Binding BugNo}" />
<local:DataGridTextColumn Header="Activity" Binding="{Binding TaskName}" />
<local:DataGridTextColumn Header="Monday" Binding="{Binding Monday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Tuesday" Binding="{Binding Tuesday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Wednesday" Binding="{Binding Wednesday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Thursday" Binding="{Binding Thursday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Friday" Binding="{Binding Friday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Saturday" Binding="{Binding Saturday, Mode=TwoWay}" />
<local:DataGridTextColumn Header="Sunday" Binding="{Binding Sunday, Mode=TwoWay}" />
</local:DataGrid.Columns>
</local:DataGrid>
<Button Name="AddBugBtn" Width="125" Height="25" Content="Add From Bugzilla" Click="AddBug_Click" Grid.Row="3" HorizontalAlignment="Right"></Button>
<Button Name="SaveBtn" Width="125" Height="25" Content="Save" Click="Save_Click" Grid.Row="3" HorizontalAlignment="Left"></Button>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎有过多的 RowDefinitions,您没有向 Grid.Row="1" 分配任何内容。也许您应该消除此行并调整元素上的 Grid.Row 分配。我还建议您将最后一个 RowDefinition 的高度设置为
Auto
并从外部网格中删除Height="Auto"
。You seem to have an excess of RowDefinitions, you aren't assigning anything to
Grid.Row="1"
. Perhaps you should eliminate this row and adjust the Grid.Row assignments on your elements. I would also suggest that you set the last RowDefinition's height toAuto
and get rid ofHeight="Auto"
from the outer Grid.