Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF ListView Live Grouping

$
0
0

I have a listview with dynamic grouping, the code I use to add group descriptions is .

  PropertyGroupDescription groupDescription = new PropertyGroupDescription("CheckSum");
            view = (CollectionView)CollectionViewSource.GetDefaultView(SourceList);
            if (view != null)
            view.GroupDescriptions.Add(groupDescription);

I would like the grouping to be live but have not been able to figure out how to do it. When I try to use ICollectionViewLiveShaping with the same code, it does nothing.

Here is the value converter i am using, it is to convert MD5 values into group names(e.g Group 1, Group 2) etc. It is working fine but after a lot of scrolling top the top and bottom of the list disturbs the order of grouping.

class GroupNameConverter : IValueConverter
    {

        public  int i = 0;
       
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

        
             if (i <= MainWindow.CheckSums.Count-1)
            {
                i++;

                return "Group " + i.ToString();
            }


            else
            {

                i--;

                return "Group " + i.ToString();

            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }

The grouping is fine at first, but after scrolling up and down the group names get all out of order.

I know the problem could be in the value converter but cant figure out how to fix it. Any help will be greatly appreciated.


Viewing all articles
Browse latest Browse all 18858


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>