C
C#15mo 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
cap5lut15mo 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
ElioOP15mo ago
ok thanks for the info i will look into it 🙂
Accord
Accord15mo 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.
Want results from more Discord servers?
Add your server