Silverlight DataGrid 无法拉伸以容纳数据源中的所有项目?

发布于 2024-08-31 01:10:24 字数 3688 浏览 5 评论 0原文

我在让 Silverlight DataGrid 拉伸以容纳其数据源中的所有项目时遇到问题。 我有一个包含两个 DataGrid 的网格。 我尝试在网格和数据网格上设置 height=Auto 。 我尝试在网格和数据网格上设置 Horizo​​ntalContentAlignment="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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骷髅 2024-09-07 01:10:24

您似乎有过多的 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 to Auto and get rid of Height="Auto" from the outer Grid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文