How to save the IsExpanded state in group headers of a listview

前端 未结 3 868
不思量自难忘°
不思量自难忘° 2020-12-03 03:18

I have quite a tricky problem:

I am using a ListView control with the ItemsSource set to a CollectionViewSource including a PropertyGroupDescription to group the Lis

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 04:08

    You could create a new class with a Dictionary (say, ObjectType as a key to bool values), and give it an indexer:

        Dictionary expandStates = new Dictionary();
    
        public bool this[ObjectType key]
        {
            get
            {
                if (!expandStates.ContainsKey(key)) return false;
                return expandStates[key];
            }
            set
            {
                expandStates[key] = value;
            }
        }
    

    Then, instantiate it in a ResourceDictionary somewhere and bind the IsExpanded to it like this:

    
    

    That might well do it: a nice way of getting WPF to call your code and pass a parameter just when you need it. (That WPF lets you put subexpressions in indexers in a binding path was news to me - good though isn't it!)

提交回复
热议问题