What I still have: A WPF application using MVVM, IDataErrorInfo. Everything works as expected.
Each time I open the "Create a new entity" dialog, the user is saluted with a beautiful shape that flashes red all over the place. This is expected from a pure point of view, but it is annoying, and I would like to be able to do one of two things.
- “Soften” the highlight color with a red error so that you can say orange or yellow to indicate “Required field”. Subsequently, when the user begins to interact with the control switch with red backlight
- If this is not possible, is there a way to disable error highlighting @ initial state?
I found this post. How can I get WPF NOT to display validation errors when initially displaying the controls? , considering the same problem, but did not answer it.
I considered implementing the "Clear All Error" implementation in my implementation of IDataErrorInfo, as well as the implementation of the InitialState flag, so the errors will not be added until the user changes at least one field, but they have side effects.
- If I clear all errors after init, the check will be disabled, but the submit button, of course, is turned on :(
- If I use the InitialState flag, which is also associated with the submit button, to disable it ... I take one more step, but then ALL errors are added with a change in one property field.
So, before I go over and add the InitState flags for the EACH property, although I will stop and ask if there could be a simpler and more general solution for this.
I can send the code if required. However, I implement IDataErrorInfo in the standard way, Dictionary<string,string> for error messages, property fields with OnChange events, and a case switch statement to invoke individual validation methods.
EDIT: That's what I ended up with.
- I added the flag
IsInitState=true for each property of the Required field in VM In the installer code, this flag is false on the first change
if (Name != value) { Name = value; IsInitState_Name = false; base.OnPropertyChanged("Name"); }
In ValidateName (), a Null / empty check is conditional based on a flag
if (! IsInitState_Name && String.IsNullOrEmpty (this.Name))
The submit button "canExecute" checks if all flags are == false before enabling submit
This is additional work, but it is necessary only for the “required / non-zero features” properties. Now the new Create interface is initially without error messages, but the check is fully functional.
source share