c# - Retrieving IDataErrorInfo string result in viewmodel -
How can I get the string from my ViewModel using the IDataErrorInfo.this [string propertyName] method?
Basically, I have created a new property inside the model, so I can validate each line in the model collection, and on my vaildation check, I would say whether it is legitimate or not and If not, then it will be disabled in my viewmodel command
model
string IDataErrorInfo.this [string propertyName] {get {// Vaildation logic if (result! String.Empty) {IsValid = false; } And {IsValid = true; } Return results; }
View modell
public bool CanSave {get (if m_ProductVersion! = Null & amp; m_ProductVersion.ProductItems! = Null) {foreach (in ProductItem item M_ProductVersion.ProductItems) // // I do not want to use anymore if there is more (! Item.IsValid return false); True} true; }}
But I would like to get rid of the isValid property if I could use the result and IDUIRINFOIN inside Viomodalal.
Can this be done?
Thanks
First of all, note that your IsValid
is not working correctly Imagine that you have 3 properties that you want to validate: A
, b
and C
. WPF usually evaluates IDataErrorInfo
, whenever you enter something, think that I have something invalid for A
and B
. I get an error and IsValid
will be false
. So far, so good. Now, I have something valid for C
a
and b
is still invalid, but IsValid
is now true - Because the result of the last idataErrorInfo
is empty.
Then your IsValid
checks the valid last property, which is certainly not sufficient for general validity investigation.
Before applying to a property IsValid
, you should run the verification for every property something like this:
Public bool isvalid () {for allPropertyNames in string propertyName} {if (! String.IsEmptyOrNull ((IDataErrorInfo) this) [propertyName]) return false; } Back true; }
You need to maintain a list of all property names so that we can repeat through those people. Then we represent the verification of the this [property name]
, which calls IDataErrorInfo
validation. If we receive any error, then the object is not valid.
So, as you can see, you can simply check the Single property by calling IDataErrorInfo
property property, but usually Want to do a check for all properties.
Comments
Post a Comment