C
C#11mo ago
Elio

❔ Display error message if value out of limit

Hi, i'm using wpf with mvvm pattern and i'd like to know if it's good to do this in order to display a message error if the value enter isn't good :
public class StepNormalViewModel : StepViewModel
{
private readonly StepNormal _stepNormal;

private double _aV;
public double AV
{
get => _aV;
set
{
if(StepCheck.CheckAV(_aV))
{
_stepNormal.AV = _aV;
_aV = value;
OnPropertyChanged();
}
else
{
//*Display my Error forms*
}
}
}
}
public class StepNormalViewModel : StepViewModel
{
private readonly StepNormal _stepNormal;

private double _aV;
public double AV
{
get => _aV;
set
{
if(StepCheck.CheckAV(_aV))
{
_stepNormal.AV = _aV;
_aV = value;
OnPropertyChanged();
}
else
{
//*Display my Error forms*
}
}
}
}
3 Replies
cap5lut
cap5lut11mo ago
afaik, usually u have an extra property for the validity state and validation errors u would bind to ur view and simply set these in ur setter. so basically the displaying the error would be something like
else
{
AvIsValid = false;
AvValidationErrorMessage = "aint a valid value cuz blah";
]
else
{
AvIsValid = false;
AvValidationErrorMessage = "aint a valid value cuz blah";
]
tho i never used wpf, it might have something built-in for this as well
Elio
Elio11mo ago
ok thanks for the info i will look into it 🙂
Accord
Accord11mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.