-1

I have a class where I define one property normally as follows:

public class MeasurementPoint : ModelBase
{
    private double _value;
    public double Value
    {
        get { return _value; }
        set
        {
            _value = value;
            NotifyPropertyChanged();
        }
    }
}

Next I have created a collection which contains many of the 'MeasurementPoint' objects. I would want to raise the notifyPropertyChanged on every object which meets certain value logic.

At the moment this method works, and the propertyChanged is raised. However, surely there is a more efficient way to do this?

private void RefreshDataGridTolerance()
{
    foreach (var measurementPoint in DataSet)
    {
        //TODO: Change this into a real way to raiseproperty changed without actually changing the value
        var temp = measurementPoint.Value;
        measurementPoint.Value = temp;

        // something like this doesnt work?
        // RaisePropertyChanged(nameof(measurementPoint.Value));
    }
}

The collection is defined as follows: ObservableCollection<MeasurementPoint> DataSet

ajr
  • 874
  • 2
  • 13
  • 29

1 Answers1

3

You could implement a public method in your model class that will raise the property changed event for every defined property. The cheapest approach could be this:

public class MeasurementPoint : ModelBase
{
  //...
  public void RefreshAllProperties()
  {
    foreach(var prop in this.GetType().GetProperties())
      this.OnPropertyChanged(prop.Name);
  }
}

you can refresh bindings of one data element like this.

var element = DataSet.First();
element.RefreshAllProperties();