Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5938715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:43:30+00:00 2026-05-22T15:43:30+00:00

I have a ListView Control bound to a ListCollectionView in a ViewModel. I wanted

  • 0

I have a ListView Control bound to a ListCollectionView in a ViewModel.

I wanted to try to group these items but having some problems.

I set the Property grouping in the VM to begin with and then added a GroupStyle.

C#:

ListCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("Category"));

XAML:

<ListView.GroupStyle>
    <GroupStyle>
        <GroupStyle.HeaderTemplate>
            <DataTemplate>
                 <TextBlock Text="{Binding Path=Name}"/>
            </DataTemplate>
        </GroupStyle.HeaderTemplate>
    </GroupStyle>
</ListView.GroupStyle>

However the list is now just the category names, no way to see the items themselves.

I’m not really understanding completely what is going on here. When I create a Template for the GroupStyle what am I really binding to? Are there other properties besides Name ?

I just added the GroupStyle to a ListView I has already created where I for example included a ItemTemplate. Is that something that is messing with the GroupStyle?

What if the Items in the list belong to another class and I wan’t to group based on what instance of class they belong to (it has an ID). I would then have the group name as a property on this parent class. Is that possible?

PARTIAL SOLUTION:

Problem was with the style applied on the ListView. I have no idea what about the style was interefering.

FULL SOLUTION

I wasn’t using a ItemsPresenter in my listbox ControlTemplate opting to use a Panel with IsItemsHost set to true. It seems ItemsPresenter must be used for GroupStyling to work correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:43:30+00:00Added an answer on May 22, 2026 at 3:43 pm

    I think the error lies elsewhere in your code.

    Usually, you expose a collection of Models on your ViewModel

    namespace Derp
    {
        public sealed class ViewModel
        {
          public ObservableCollection<Model> Items {get;set;}
          // initialization code not shown
        }
    
        public sealed class Model
        {
          public string GroupName {get;set;}
          public string ModelName {get;set;}
        }
    }
    

    In your View, you bind a CollectionViewSource to this collection:

    <Window.DataContext>
        <ViewModel xmlns="clr-namespace:Derp" />
    </Window.DataContext>
    <Window.Resources>
        <CollectionViewSource
            Source="{Binding Items}"
            x:Key="GroupedItems">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription
                    PropertyName="GroupName" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    </Window.Resources>
    

    Next, we bind our list control to this CollectionViewSource (using a combo in this example):

    <ComboBox
        ItemsSource="{Binding Source={StaticResource GroupedItems}}"
        DisplayMemberPath="ModelName">
        <ComboBox.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock
                            Text="{Binding Name}" />
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </ComboBox.GroupStyle>
    </ComboBox>
    

    Where it can get confusing is that, within the GroupStyle, you aren’t binding against your Model, you are binding against a collection of Models which is grouped on (in this case) the property “GroupName“. The CollectionViewSource groups your Models into collections that extend CollectionViewGroup. These groups have a property called Name, which contains the common value on which your Models are grouped (the value of the GroupName property). So, in the HeaderTemplate, you are binding to CollectionViewGroup.Name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQLDataSource that is bound to a ListView control but I want
I have a listview control that is bound to an observable collection that I
I've got a ListView control bound to an ObservableCollection of items, and I've set
I have an asp:ListView control on an ASP.NET page. It is bound to an
I have a button on a listview control. I have bound this control to
I have a ListView control, and I'm trying to figure out the easiest/best way
I have a ListView control that is in FullRowSelect mode, MultiSelect off and using
Can you have a multicolumn listview control where one of the columns is a
I have a ListView which sometimes I need to put around 10000 items in.
I have a ListView containing file names. These file names need to be draggable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.