C# WPF组样式错误

C# WPF组样式错误,c#,wpf,xaml,datagrid,grouping,C#,Wpf,Xaml,Datagrid,Grouping,我在DataGrid中有一个GroupStyle,如下所示: <DataGrid x:Name="CompassLogDataGrid" ItemsSource="{Binding Source={StaticResource Compasscollection}, IsAsync=True, Mode=OneTime}" Height="auto" AutoGenerateColumns="False" Style="{Dy

我在
DataGrid
中有一个
GroupStyle
,如下所示:

<DataGrid x:Name="CompassLogDataGrid"
    ItemsSource="{Binding Source={StaticResource Compasscollection}, IsAsync=True,                 Mode=OneTime}"
    Height="auto"
    AutoGenerateColumns="False"
    Style="{DynamicResource ResourceKey=Log4NetDataGridStyle}">

      <DataGrid.GroupStyle>
          <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}" />
      </DataGrid.GroupStyle>
      ...
</DataGrid>
此代码产生以下
错误

System.Windows.Data错误:4:找不到引用为“RelativeSource FindAncestor,AncestorType='System.Windows.Controls.DataGrid',AncestorLevel='1'的绑定源。BindingExpression:Path=AreRowDetailsFrozen;DataItem=null;目标元素是“DataGridDetailsPresenter”(名称=“”);目标属性为“SelectiveScrollingOrientation”(类型为“SelectiveScrollingOrientation”) System.Windows.Data错误:4:找不到引用为“RelativeSource FindAncestor,AncestorType='System.Windows.Controls.DataGrid',AncestorLevel='1'的绑定源。BindingExpression:Path=HeadersVisibility;DataItem=null;目标元素是“DataGridRowHeader”(名称=“”);目标属性为“可见性”(类型为“可见性”)


我怎样才能解决这个问题

我不认为这是一个分组或风格问题。我已经厌倦了你的风格,它在我的
DataGrid
上运行得很好。
    <Style x:Key="GroupHeaderStyle"
       TargetType="{x:Type GroupItem}">

    <Setter Property="OverridesDefaultStyle"
            Value="False" />

    <Setter Property="Margin"
            Value="0,0,0,5" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type GroupItem}">
                <Expander IsExpanded="False"
                          Background="#FF112255"
                          BorderBrush="#FF002255"
                          Foreground="Black"
                          BorderThickness="1,1,1,5">
                    <Expander.Header>
                        <DockPanel>
                            <TextBlock FontWeight="Bold"
                                       Foreground="White"
                                       Text="{Binding Path=Name}"
                                       Margin="5,0,0,0"
                                       Width="100" />
                            <TextBlock FontWeight="Bold"
                                       Foreground="White"
                                       Text="{Binding Path=ItemCount}" />
                        </DockPanel>
                    </Expander.Header>

                    <Expander.Content>
                        <ItemsPresenter />
                    </Expander.Content>
                </Expander>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>