I have a WPF ListView/GridViwe in a MVVM application. GridView is bound to a List in the ViewModel.
The requirement is that the users should be able to select multiple rows of the gridview, right-click on it and see a context menu "Group These Together". Once selected, all these items should be collapsed into one group with a expander or + sign added at the beginning.
Can somebody please help me in getting this working?
I was working on similar problem, but I had to group items by their let's say name. What I've done was create
DataTrigger
orMultiDataTrigger
depending on your data requirements and then when conditions are true i.e. item selected change the container forGroupItem
. What I mean is when you create your list view, you have to create it with grouped view, which btw is not grouped as you can declare it withoutexpander
and just use theStackPanel
. After that you need 3 lines of Code to set the grouping. Here is an example for you:MAIN.xaml
As you can see I have declared an empty container for the grouped style, reson why is because you can't assign it without previous declaration. After this declaration you need this in your
generic.xaml
After you declared your style for the true value you need to declare one for without
expander
Next step is to define the grouping:
Which should apper in your
ViewModel
. Good luck! Let us know if you need any more help, I'll try my best with my English ;-)EDIT
I forgot to mention when you assign the grouping you need to check the number of groups already in the collection and only apply it when there is non or 0, otherwise you'll apply the grouping multiple times and the expander will be repeeated in the result window as many times as you added the grouping :-)
What in my mind to select multiple row Ctrl+click
It will select multiple row and on right click open a context menu after setting its Isopen to true
You should also bind selected item to list and Use this item to make an expander