开发者

Silverlight DataGrid not stretching to accommodate all items in data source?

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.D开发者_开发技巧ata" 
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>


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 to Auto and get rid of Height="Auto" from the outer Grid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜