我在使用Silverlight DataGrid进行拉伸以容纳其dataSource中的所有项目时遇到问题。 我有一个包含两个DataGrids的Grid。 我已经尝试在Grid和DataGrids上设置height = Auto。 我已经尝试在Grid和DataGrids上设置HorizontalContentAlignment =“Stretch”。 object标签有height =“100%” 我在Grid的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>
答案 0 :(得分:0)
您似乎有过多的RowDefinitions,您没有为Grid.Row="1"
分配任何内容。也许您应该消除此行并调整元素上的Grid.Row分配。我还建议您将最后一个RowDefinition的高度设置为Auto
,并从外部网格中删除Height="Auto"
。