silverlight调整datagrid datagridsplitter

时间:2011-06-21 11:14:03

标签: silverlight datagrid resize

我正在尝试使用gridsplitter来调整网格行的大小,但我没有得到我期望的行为。

    <Grid x:Name="LayoutRoot" Background="White" Width="300">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0">
        <StackPanel Orientation="Horizontal">
            <TextBlock Height="23" Text="Inventory:"/>
        </StackPanel>
        <sdk:DataGrid AutoGenerateColumns="False" Height="Auto" Name="dataGrid1" HorizontalAlignment="Left"  IsReadOnly="True" >
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding Name}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Name" IsReadOnly="True" />
                <sdk:DataGridTextColumn Binding="{Binding CreatedDate}" Header="Created Date" />
                <sdk:DataGridTextColumn Binding="{Binding ChangedDate}" Header="Last Edited" />
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
    </StackPanel>        
    <sdk:GridSplitter Grid.Row="1" Height="10" Width="300"  HorizontalAlignment="Stretch"/>
    <Grid Grid.Row="2"></Grid>
</Grid>

在移动分离器之前 enter image description here

移动分离器后 enter image description here

我希望datagrid调整其内容的大小,在调整大小时应该有一个滚动条。

1 个答案:

答案 0 :(得分:1)

问题是您在StackPanel中拥有DataGrid。垂直方向的堆栈面板没有垂直边界,因此数据网格使其全高度不知道它将被剪裁。您应该使用另一个网格来获得所需的结果: -

   <Grid x:Name="LayoutRoot" Background="White" Width="300">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
       <Grid.RowDefinitions>
           <RowDefinition Height="Auto" />
           <RowDefinition Height="*" />
       </Grid.RowDefinitions>
       <TextBlock Grid.Row="0" Height="23" Text="Inventory:"/>
       <sdk:DataGrid Grid.Row="1" AutoGenerateColumns="False" Name="dataGrid1" HorizontalAlignment="Left"  IsReadOnly="True" >
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding Name}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Name" IsReadOnly="True" />
                <sdk:DataGridTextColumn Binding="{Binding CreatedDate}" Header="Created Date" />
                <sdk:DataGridTextColumn Binding="{Binding ChangedDate}" Header="Last Edited" />
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
    </Grid>        
    <sdk:GridSplitter Grid.Row="1" Height="10" Width="300"  HorizontalAlignment="Stretch"/>
    <Grid Grid.Row="2"></Grid>
</Grid>