2016-11-15 53 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上也有一個名稱屬性。 –