WPF DataGrid CustomSort for each Column

后端 未结 10 1491
庸人自扰
庸人自扰 2020-12-01 01:56

I have a WPF DataGrid bound to a CollectionViewSource that encapsulates an ObservableCollection. This CollectionViewSource has two main objectives:

1) To group each

10条回答
  •  被撕碎了的回忆
    2020-12-01 02:12

    The answer given by trilson86 is excellent. However, the third parameter in the two DependencyProperty declarations is incorrect. Instead of DataGrid and DataGridColumn, they should be CustomSortBehaviour, as such:

    public static readonly DependencyProperty AllowCustomSortProperty =
            DependencyProperty.RegisterAttached("AllowCustomSort", 
            typeof(bool),
            typeof(CustomSortBehaviour), // <- Here
            new UIPropertyMetadata(false, OnAllowCustomSortChanged));
    
        public static readonly DependencyProperty CustomSorterProperty =
            DependencyProperty.RegisterAttached("CustomSorter", 
            typeof(ICustomSorter), 
            typeof(CustomSortBehaviour));  // <- Here
    

    I kept getting a warning that the AllowCustomSort property was already registered. A little research led me to the answer here.

    At any rate, it's an excellent answer, so thank you.

提交回复
热议问题