none
WPF 自动布局问题,有两个横向的DataGrid控件 RRS feed

  • 问题

  • 我的界面是这样的,主要是右侧,用gird布局,共三行,1,2行是DataGrid,3行是固定高度的

    界面XAML:

    <Grid Background="BlueViolet">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" MinHeight="200"/>
                    <RowDefinition Height="*" MinHeight="200"/>
                    <RowDefinition Height="90"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <DataGrid Grid.Row="0" x:Name="Products" AutoGenerateColumns="False">
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding Path=Number}" Header="VJia编号"></DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Path=Name}" Header="宝贝名称"></DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Path=Price}" Header="宝贝价格"></DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Path=Expire}" Header="有效期"></DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Path=Freighter}" Header="谁邮寄"></DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Path=Freight}" Header="邮费(平邮,EMS,快递)"></DataGridTextColumn>
                    </DataGrid.Columns>
                </DataGrid>
                <DataGrid Grid.Row="1" x:Name="VJiaItems"  AutoGenerateColumns="False">
                        <DataGrid.Columns>
                            <DataGridHyperlinkColumn  Binding="{Binding Path=Url}"  ContentBinding="{Binding Path=Number}" Header="VJia编号"></DataGridHyperlinkColumn>
                            <DataGridTextColumn Binding="{Binding Path=SpecialPrice}" Header="优惠价格"></DataGridTextColumn>
                            <DataGridTextColumn Binding="{Binding Path=VJiaPrice}" Header="VJia价格"></DataGridTextColumn>
                            <DataGridTextColumn Binding="{Binding Path=MarketPrice}" Header="市场价格"></DataGridTextColumn>
                            <DataGridTextColumn Binding="{Binding Path=Starts}" Header="评分"></DataGridTextColumn>
                            <DataGridTextColumn Binding="{Binding Path=CommentsCount}" Header="评论数量"></DataGridTextColumn>
                            <DataGridTextColumn Binding="{Binding Path=Love}" Header="喜欢"></DataGridTextColumn>
                            <DataGridTextColumn Binding="{Binding Path=Common}" Header="一般"></DataGridTextColumn>
                            <DataGridTextColumn Binding="{Binding Path=Bad}" Header="不好"></DataGridTextColumn>
                        </DataGrid.Columns>
                    </DataGrid>
            <TextBlock Grid.Row="2" x:Name="txbResult" HorizontalAlignment="Left" Height="30" TextWrapping="Wrap" Text="tip" Width="120"  Margin="5"/>
                <Button Grid.Row="2" Content="Open CVS" HorizontalAlignment="Left" Width="120" Click="OpenCVS" Background="#FF638270" Margin="200,5,5,5"/>
                <Button Grid.Row="2" Content="Search VJia" HorizontalAlignment="Left" Width="120" Click="SearchVJia" Background="#FF638270" Margin="350,5,5,5"/>
            </Grid>

    填充数据 以后是这样:

    希望达到的效果是,上面两个DataGrid评分第三行外的剩余高度,不填充数据的时候是正常的,填充完就撑破了


    forget flying

    2012年6月1日 3:48

答案

  • 所以你的第三行应该是 高度 = auto, 你的第一第二行的最小高度是否太大了,小一点可能在窗体较小时还能够显示出第三行的内容:

        <Grid.RowDefinitions>
          <RowDefinition Height="*" MinHeight="200"/>
          <RowDefinition Height="*" MinHeight="200"/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us


    2012年6月1日 7:33
    版主