I have the following class:
public class Numbers :INotifyPropertyChanged
{
private double _Max;
public double Max
{
get
{
return this._Max;
}
set
{
if (value >= _Min)
{
this._Max = value;
this.NotifyPropertyChanged("Max");
}
}
}
private double _Min;
public double Min
{
get
{
return this._Min;
}
set
{
if (value <= Max)
{
this._Min = value;
this.NotifyPropertyChanged("Min");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (this.PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
Problem: I dont want to allow user to enter max value less than min value and so on. But above code is not working for the first time when other class try to set min / max value when min / max value has default value of zero.
Since by default min and max value will be zero, if min value is set > 0 which is logically correct but the constraint is not allowed to do that.
I think I need to solve this using dependent property or coercion. Could anyone guide to do that?
You could back it by a Nullable so it becomes this: