2017-01-19 28 views
0

我想使用CollectionViewSource将我的ObservableCollection分组,它似乎适用于项目,但它没有显示GroupBox的绑定属性值。在ItemsControl中分组后不显示组标题后显示

这里是我尝试:含

我已经List<Object>的属性描述,季节。我想按季节分组。这里是我的xml:

<mah:MetroWindow x:Class="eCatalog_Launcher.MainWindow" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:local="clr-namespace:eCatalog_Launcher" 
      xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" 
      xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" 
      mc:Ignorable="d" 
      Title="eCatalog Launcher" 
      WindowState="Maximized" 
      Loaded="MetroWindow_Loaded" 
      Closing="MetroWindow_Closing"> 

<Window.Resources> 
    <CollectionViewSource x:Key="catalogsBySeasons" 
          Source="{Binding Path=Catalogs, Mode=TwoWay}"> 
     <CollectionViewSource.GroupDescriptions> 
      <PropertyGroupDescription PropertyName="Season" /> 
     </CollectionViewSource.GroupDescriptions> 
    </CollectionViewSource> 

</Window.Resources> 

<ScrollViewer> 
    <ItemsControl ItemsSource="{Binding Source={StaticResource catalogsBySeasons}}"> 
     <ItemsControl.GroupStyle> 
      <GroupStyle> 
       <GroupStyle.ContainerStyle> 
        <Style TargetType="{x:Type GroupItem}"> 
         <Setter Property="Template"> 
          <Setter.Value> 
           <ControlTemplate TargetType="{x:Type GroupItem}"> 
            <GroupBox Header="{Binding Season}"> 
             <ItemsPresenter /> 
            </GroupBox> 
           </ControlTemplate> 
          </Setter.Value> 
         </Setter> 
        </Style> 
       </GroupStyle.ContainerStyle> 
      </GroupStyle> 
     </ItemsControl.GroupStyle> 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
       <mah:Tile Title="{Binding Description}" 
          Tag="{Binding}" 
          Style="{StaticResource SmallTileStyle}" 
          Click="Tile_Click"> 
        <iconPacks:PackIconMaterial Width="32" 
               Height="32" 
               Margin="0, -30, 0, 0" 
               Kind="{Binding Kind}"> 
        </iconPacks:PackIconMaterial> 
       </mah:Tile> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
     <ItemsControl.ItemsPanel> 
      <ItemsPanelTemplate> 
       <WrapPanel /> 
      </ItemsPanelTemplate> 
     </ItemsControl.ItemsPanel> 
    </ItemsControl> 
</StackPanel> 

它显示为GroupBox标题季节值。 有什么不对吗?

回答

1

你应该绑定到组的名称属性:

<ControlTemplate TargetType="{x:Type GroupItem}"> 
    <GroupBox Header="{Binding Name}"> 
     <ItemsPresenter /> 
    </GroupBox> 
</ControlTemplate> 

这应该显示季节财产的实际价值,你GROUP BY。

+0

是的,它使用'Name'正常工作。谢谢! – Saadi