Set event on object's parameter updated in observable collection

21 Views Asked by At

As for question, I have an ObservableCollection of objects, declared in a UserControl and binded to an ItemsControl.ItemsSource.

Its properties are updated during the software run, eventually.

I would like to catch the update event.

I tried using the CollectionChanged event, but it isn't fired.

The collection is declared as belove:

    public ObservableCollection<BatchSensor> BatchSensors
    {
        get { return (ObservableCollection<BatchSensor>)GetValue(BatchSensorsProperty); }
        set { SetValue(BatchSensorsProperty, value); }
    }
    public static readonly DependencyProperty BatchSensorsProperty =
        DependencyProperty.Register(nameof(BatchSensors), typeof(ObservableCollection<BatchSensor>), typeof(BL_BatchContainer), new UIPropertyMetadata(null));

and initialized as follows

    public BL_BatchContainer(string title, ObservableCollection<BatchSensor> batchSensors)
    {
        InitializeComponent();

        Title = title;
        BatchSensors = new ObservableCollection<BatchSensor>();

        BatchSensors.CollectionChanged += OnListChanged;

        BatchSensors = batchSensors;
    }

The class BatchSensor implements INotifyPropertyChanged and fires property change notifications.

public  class BatchSensor: ClassBase
{
    private bool? _error = null;
    public bool? Error { get => _error; set => SetAndNotifyIfChanged(ref _error, value); }
}
0

There are 0 best solutions below