I have an MVVM application where I am showing a DataGrid where the columns are bound to an ObservableCollection<DataGridColumn> in the view model.

<DataGrid AutoGenerateColumns="False" util:DataGridColumnsBehaviour.BindableColumns="{Binding Path=TagColumns}" ItemsSource="{Binding Path=TagList}"/>

One of these columns is a MaterialDesignDataGridComboBoxColumn from Material Design in XAML (v2.5.1) and when I set the ItemSource to a list directly all works as expected. However, the list I am binding to I also want to filter, so I have set up a CollectionViewSource which uses this list as it's Source, and the ItemSource of the column is set to the View.

class Model
{

    class AggregateSummary
    {
        public string Id { get; }
        public string Name { get; }
        public string Description { get; }

        public AggregateSummary(string id, string name, string description)
        {
            this.Id = id;
            this.Name = name;
            this.Description = description;
        }
    }

    public ObservableCollection<object> TagList { get; }
    public ObservableCollection<DataGridColumn> TagColumns { get; }
    public ObservableCollection<AggregateSummary> TagStatus { get; }
    public CollectionViewSource TagStatusCVS { get; }

    public Model()
    {
        this.TagColumns = ObservableCollection<DataGridColumn>();
        this.TagStatus = new ObservableCollection<AggregateSummary>
        {
            new AggregateSummary(string.Empty, "ALL", "All Statuses")
        };
        this.TagStatusCVS = new CollectionViewSource() { Source = this.TagStatus };
        this.TagStatusCVS.Filter += (sender, e) =>
        {
            var item = (AggregateSummary)e.Item;
            e.Accepted = !string.IsNullOrEmpty(item.Id);
        };

        var tagStatusColumn = new MaterialDesignDataGridComboBoxColumn()
        {
            ItemsSource = this.TagStatus, // works as expected
            //ItemsSource = this.TagStatusCVS.View, // causes all items in the grid to update at the same time
            Header = "Tag Status",
            DisplayMemberPath = nameof(AggregateSummary.Name),
            SelectedValuePath = nameof(AggregateSummary.Id),
        };
        this.TagColumns.Add(tagStatusColumn);
    }
}

As noted by the comments in the code, using a CollectionViewSource in code behind to populate the items of the combo boxes causes all the items in the grid to update at the same time.

The question is, how do I filter the original list TagStatus without ending up with this shared behaviour?

UPDATE:

I've tracked the issue down to the style that is applied to the comboboxes being generated for the column. I'm using the MaterialDesign WPF theme (v2.5.1) and the MaterialDesignDataGridComboBoxTemplate style declared seems to be causing the value of the first row to appear in all the comboboxes that are generated for the column. There is an open issue on github describing this same problem.

0

There are 0 answers