I have 4 user inputs with a 'submit' button, like this:
The for Texboxes are bound to uint variables in the viewmodel and using the 'standard' OnPropertyChanged() way, like this for example:
/// <summary>
/// Width of the exported image
/// </summary>
public uint ImageExportWidth
{
get { return imageExportWidth; }
set
{
if (value > 0 && value < 10000)
{
imageExportWidth = value;
}
else
{
GuiCommons.ModernDialogShowMessage(GeneralDefines.SizeNotSupported, DefOmegaMessageBox.OmegaException);
}
OnPropertyChanged("ImageExportWidth");
}
}
If the user presses the submit button, the values are written to a init-file, which is later used for the export process.
If now the input is invalid, already the value in the viewmodel is not updated and the feedback in the GUI looks like this:
Now, I have the following two questions:
- Since, the conversion check (to uint) isn't done by my code, I'm guessing this is a automated .NET thing? Is that enough / good practice, or do I have to make an extra check for the input myself?
- If there is an invalid input and the user presses the submit button, I want to update the textboxes in the GUI to the last valid value (which I still have saved in the corresponding viewmodel properties). What is the best way to do this using the databinding already in place?


BindingGroup.CancelEditfor that (e.g. read here).BindingGroup.CancelEdit?