2016-11-15 54 views
1

我正在显示作业。乔布斯有这样的规定:DataGrid中的绑定问题GoupStyle

public enum JobState 
{ 
    Done, 
    Running, 
    Overdue, 
    Disabled 
} 

State显示在我对他们DataGrid I组的工作,这是按预期工作。

我跟着这个example.问题是我想为StateName添加一个标头给每个分组部分。

我只是不确定GroupItemDataContext究竟是什么。

也许RelativeSource有帮助吗? - 我无法完成任何建议?


<DataGrid ItemsSource="{Binding Path=JobCollectionView}" [..]> 
    <DataGrid.GroupStyle> 
     <GroupStyle> 
      <GroupStyle.HeaderTemplate> 
       <DataTemplate> 
        <TextBlock Text="{Binding Path=State}" /> 
       </DataTemplate> 
      </GroupStyle.HeaderTemplate>     
      <GroupStyle.ContainerStyle> 
       <Style TargetType="{x:Type GroupItem}"> 
        <Setter Property="Template"> 
         <Setter.Value> 
         <ControlTemplate TargetType="{x:Type GroupItem}"> 
          <Expander IsExpanded="True"> 
            <Expander.Header> 
            <StackPanel Orientation="Horizontal"> 
        //Error is here:  <TextBlock Text="{Binding Path=StateDescription}" /> 
             <TextBlock Text="{Binding Path=ItemCount}"/> 
             <TextBlock Text=" Jobs"/> 
               </StackPanel> 
             </Expander.Header> 
            <ItemsPresenter /> 
            </Expander> 
           </ControlTemplate> 
          </Setter.Value> 
         </Setter> 
        </Style> 
      </GroupStyle.ContainerStyle> 
    </GroupStyle> 
</DataGrid.GroupStyle> 

回答

1

GroupItemDataContext是内部类名为CollectionViewGroupInternal。您已经知道该类别的项目数量为ItemCount。其余的难题 - 组的名称是由Name财产:)代表。因为这只是在你的情况枚举 - 你可以直接绑定到Name财产(它包含您的JobState枚举的一个实例)。

+0

thx。我在教程中弄错了原因,在RowLevel上也有一个名称属性。 –