如何从显示分组数据的数据网格中删除行缩进?

时间:2017-03-22 18:05:12

标签: c# wpf xaml datagrid

datagrid的Itemssource是一个ListCollectionView,它具有一个GroupDescription,用于对显示的数据进行分组。 datagrid的第一列显示每行的缩进(小灰色区域)。我已经玩了一些风格,但似乎无法摆脱行缩进。如何使每个细节行完全向左延伸(没有缩进),就像组头一样?

XAML:

<Window.Resources>
    <converter:BoolToStringMultiConverter x:Key="BoolToStringMultiConverter"/>
    <Style TargetType="DataGridColumnHeader">
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="FontWeight" Value="SemiBold"/>
    </Style>
    <Style x:Key="CenterCellTextStyle" TargetType="DataGridCell">
        <Style.Setters>
            <Setter Property="TextBlock.TextAlignment" Value="Center"/>
        </Style.Setters>
    </Style>
    <Style x:Key="DataGridIndicatorStyle" TargetType="DataGridRow">
        <Style.Triggers>
            <DataTrigger Binding="{Binding OnHold}" Value="True">
                <Setter Property="Foreground" Value="Tomato"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

<DataGrid AlternationCount="2" AlternatingRowBackground="Honeydew" AutoGenerateColumns="False" 
                  ColumnWidth="*" RowHeaderWidth="0" CanUserAddRows="False" CanUserResizeColumns="False" HeadersVisibility="Column"
                  IsSynchronizedWithCurrentItem="False" RowStyle="{StaticResource ResourceKey=DataGridIndicatorStyle}">
<DataGrid.Columns>
    <DataGridTextColumn Header="DOG">
        <DataGridTextColumn.Binding>
            <MultiBinding Converter="{StaticResource BoolToStringMultiConverter}">
                <Binding Path="DogName"/>
                <Binding Path="IsFemale"/>
                <Binding Path="HasXray"/>
            </MultiBinding>
        </DataGridTextColumn.Binding>
    </DataGridTextColumn>
    <DataGridTextColumn Header="LOCATION" Binding="{Binding PostingCity}"/>
    <DataGridTextColumn Header="IMPRINTER" Binding="{Binding LastName}"/>
    <DataGridTextColumn Binding="{Binding Age1}" CellStyle="{StaticResource CenterCellTextStyle}"/>
    <DataGridTextColumn Binding="{Binding Age2}" CellStyle="{StaticResource CenterCellTextStyle}"/>
    <DataGridTextColumn Binding="{Binding Age3}" CellStyle="{StaticResource CenterCellTextStyle}"/>
</DataGrid.Columns>
<DataGrid.GroupStyle>
    <GroupStyle>
        <GroupStyle.HeaderTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Name}" FontWeight="SemiBold" FontSize="14" VerticalAlignment="Center" 
                                           Foreground="WhiteSmoke" Background="DarkBlue"/>
                </StackPanel>
            </DataTemplate>
        </GroupStyle.HeaderTemplate>
    </GroupStyle>
</DataGrid.GroupStyle>

0 个答案:

没有答案