当autogenerateColumns设置为true时,WPF Datagrid会调整大小

时间:2016-11-01 00:27:12

标签: c# wpf datagrid

我有一个DataGrid,其中AutoGenerateColumns设置为true(Columns是动态生成的)我已将HorizontalAlignment设置为Left,以摆脱右边的额外Column

<DataTemplate x:Key="myTemplate">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
      <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <TextBlock Text="name" Margin="20,0,0,0" Grid.Row="0"/>
    <TextBlock Text="name1" Margin="20,0,0,0" Grid.Row="1"/>
    <SelectiveScrollingGrid Grid.Row="2">
      <DataGrid x:Name="ProcessParameterGrid"
                AutoGenerateColumns="True"
                ItemsSource="{Binding Path=BindingProp}"
                IsReadOnly="True"
                HorizontalAlignment="Left"
                Margin="20,0,0,10"
                CanUserSortColumns="False"
                CanUserReorderColumns="False"
                HeadersVisibility="Column"
                FrozenColumnCount="1"/>
    </SelectiveScrollingGrid>
  </Grid>
</DataTemplate>`

<ScrollViewer>
  <CustomPanel>
    <ItemsControl ItemsSource="{Binding Source={StaticResource RecipeDetailsCollectionViewSource}}"
                  VirtualizingStackPanel.IsVirtualizing="True">
      <ItemsControl.ItemTemplate>
        <DataTemplate>
          <ContentControl Content="{Binding}"
                          ContentTemplate="{StaticResource myTemplate}"
                          ScrollViewer.CanContentScroll="True"/>
        </DataTemplate>
      </ItemsControl.ItemTemplate>
    </ItemsControl>
  </CustomPanel>
</ScrollViewer>

问题: 我需要冻结Column的第一个Grid,我需要DataGrid使用父容器调整大小 - Grid。 如果我明确地为Width设置DataGrid,则会显示右侧的额外Column。我错过了什么?

0 个答案:

没有答案