我在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;)
我该如何解决这个问题?