1
我正在顯示作業。喬布斯有這樣的規定:DataGrid中的綁定問題GoupStyle
public enum JobState
{
Done,
Running,
Overdue,
Disabled
}
當State
顯示在我對他們DataGrid
I組的工作,這是按預期工作。
我跟着這個example.問題是我想爲State
的Name
添加一個標頭給每個分組部分。
我只是不確定GroupItem
的DataContext
究竟是什麼。
也許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>
thx。我在教程中弄錯了原因,在RowLevel上也有一個名稱屬性。 –