3

我有一个GroupStyle如下DataGrid所示的:

<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>

GroupStyle

    <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>

此代码产生以下内容Error

System.Windows.Data 错误:4:找不到与引用'RelativeSource FindAncestor,AncestorType='System.Windows.Controls.DataGrid',AncestorLevel='1''的绑定源。绑定表达式:路径=AreRowDetailsFrozen;数据项=空;目标元素是'DataGridDetailsPresenter'(名称='');目标属性是“SelectiveScrollingOrientation”(类型为“SelectiveScrollingOrientation”) System.Windows.Data 错误:4:找不到用于绑定参考的源“RelativeSource FindAncestor,AncestorType='System.Windows.Controls.DataGrid',AncestorLevel='1'” . BindingExpression:Path=HeadersVisibility; 数据项=空;目标元素是'DataGridRowHeader'(名称='');目标属性是“可见性”(类型“可见性”)

我怎样才能解决这个问题?

4

0 回答 0