WPF items not visible when grouping is applied

Posted by Tri Q on Stack Overflow See other posts from Stack Overflow or by Tri Q
Published on 2009-10-09T06:47:04Z Indexed on 2010/05/25 23:11 UTC
Read the original article Hit count: 297

Filed under:
|
|
|

Hi,

I'm having this strange issue with my ItemsControl grouping. I have the following setup:

<ItemsControl Margin="3" ItemsSource="{Binding Communications.View}" >
    <ItemsControl.GroupStyle>
        <GroupStyle>
            <GroupStyle.ContainerStyle>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                <Expander>
                                    <Expander.Header>
                                        <Grid>
                                            <Grid.ColumnDefinitions >
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Text="{Binding ItemCount, StringFormat='{}[{0}] '}" FontWeight="Bold" />
                                            <TextBlock Grid.Column="1" Text="{Binding Name, Converter={StaticResource GroupingFormatter}, StringFormat='{}Subject: {0}'}" FontWeight="Bold" />
                                        </Grid>
                                    </Expander.Header>
                                    <ItemsPresenter />
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>
    </ItemsControl.GroupStyle>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock FontWeight="Bold" Text="{Binding Inspector, Converter={StaticResource NameFormatter}, StringFormat='{}From {0}:'}" Margin="3" />
                <TextBlock Text="{Binding SentDate, StringFormat='{}{0:dd/MM/yy}'}" Grid.Row="1" Margin="3"/>
                <TextBlock Text="{Binding Message }" Grid.Column="1" Grid.RowSpan="2" Margin="3"/>
                <Button Command="vm:CommunicationViewModel.DeleteMessageCommand" CommandParameter="{Binding}"  HorizontalAlignment="Right" Grid.Column="2">Delete</Button>
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

In my ViewModel, I expose a CollectionViewSource named 'Communications'. I proceed to adding a grouping patter like so:

Communications.GroupDescriptions.Add(new PropertyGroupDescription("Subject"));

Now, the problem i'm experience is the grouping work fine, but I can't see any items inside the groups. What am I doing wrong? Any pointers would be much appreciated.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about grouping