Silverlight 3 Validation - does manual validation not work?

Apologies for the cross-posts (I asked this at the Silverlight Forum , but received no reply)

I have an entity that I am trying to use for verification, so I decorated this property:

[Required]
[StringLength(10)]
public string Code
{
get
{
return this.code;
}

set
{
if (this.code != value)
{
this.code = value;
this.SendPropertyChanged("Code");
}
}
}

I have a list of these gridded objects. If I put an empty entry, it shows a validation error. If I add code too long, I get a validation error. Fine! With the exception of...

I want the user to not be able to save the object, so I added the following to my object:

public bool IsValid()
{
    try
    {
        this.Validate();
    }
    catch
    {
        return false;
    }
    return true;
}

public void Validate()
{
    var ctx = new ValidationContext(this, null, null);
    Validator.ValidateObject(this, ctx);
}

, IsValid false. ( , ), StringLength ( ).

:

http://walkersretreat.co.nz/files/Slvalidation.zip

- ?

!

+3
1

:

[CustomValidation( typeof( MyExtraClassValidation ), "Validate" )]
public class MyExtraClass : Entity, IEditableObject, INotifyPropertyChanged
{
   /****/
}


public class MyExtraClassValidation 
{
    public MyExtraClassValidation ()
    {}

    public static ValidationResult Validate( MyExtraClass myExtraClass )
    {
        if ( /**class is not valid*/)
            return new ValidationResult( "Oops" );

        return ValidationResult.Success;
    }

}

, , .

, validateHandler , , .

0

Source: https://habr.com/ru/post/1718848/


All Articles