2010-04-30 41 views
1

我有問題讓Silverlight DataGrid伸展來容納它的dataSource中的所有項目。 我有一個包含兩個DataGrid的網格。 我試着在Grid和DataGrid上設置height = Auto。 我試着在Grid和DataGrid上設置Horizo​​ntalContentAlignment =「Stretch」。 對象標籤有height =「100%」 我已經在Grid的RowDefinitions上設置了Height =「*」Silverlight DataGrid無法伸縮以容納數據源中的所有項目?

任何幫助將非常感謝!

下面的代碼清單:

<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

它不清楚哪個方向不適合?水平還是垂直? – AnthonyWJones 2010-04-30 13:40:36

回答

0

你似乎有過量RowDefinitions,你是不是分配什麼Grid.Row="1"的。也許你應該消除這一行,並調整你的元素的Grid.Row分配。我還建議您將最後一個RowDefinition的高度設置爲Auto,並從外部網格中刪除Height="Auto"

+0

謝謝你,我會試一試。 – bplus 2010-04-30 15:48:10

相關問題