WPF GroupStyle错误

时间:2013-03-22 10:04:51

标签: c# wpf xaml datagrid grouping

我在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:无法找到带引用的绑定源&#39; RelativeSource FindAncestor,AncestorType =&#39; System.Windows.Controls.DataGrid&#39;,AncestorLevel =&#39; 1& #39;&#39 ;. BindingExpression:路径= AreRowDetailsFrozen;的DataItem = NULL;目标元素是&#39; DataGridDetailsPresenter&#39; (名称=&#39;&#39);目标属性是'SelectiveScrollingOrientation&#39; (键入&#39; SelectiveScrollingOrientation&#39;)       System.Windows.Data错误:4:找不到用于引用绑定的源&#39; RelativeSource FindAncestor,AncestorType =&#39; System.Windows.Controls.DataGrid&#39;,AncestorLevel =&#39; 1&#39; &#39 ;. BindingExpression:路径= HeadersVisibility;的DataItem = NULL;目标元素是&#39; DataGridRowHeader&#39; (名称=&#39;&#39);目标财产是“可见性”&#39; (键入&#39;可见性&#39;)

我该如何解决这个问题?

0 个答案:

没有答案