Static Class Property getting NULL when Custom Validation fired in Silverlight 4 - MVVM

Deadly 提交于 2019-12-13 03:58:44

问题


1. I have created Test Class which contain Static Class and Property.

namespace QSys.Data.Domain.DataSecurity
{
    public static class TestData
    {
        public static string MyName { get; set; }
    }
}

2. Customer Model class and Custom Validation

namespace QSys.Data.Domain
{
    [Serializable()]
    public class Customer
    {
        [Key]
        public virtual int Id { get; set; }
        [CustomValidation(typeof(CustomerRequiredRules), "IsCompanyNameEmpty")]
        public virtual string CompanyName { get; set; }
        public virtual string City { get; set; }
    }

    public class CustomerRequiredRules
    {
        public static ValidationResult IsCompanyNameEmpty(string CompanyName, ValidationContext context)
        {
            if (TestData.MyName == "Imdadhusen")
            {
                return new ValidationResult("Company name not allowed!", new string[] { "CompanyName" });
            }
            return ValidationResult.Success;
        }
    }
}

3. Setting value of Static class like

public class AdminHomeViewModel 
{
   public AdminHomeViewModel()
   {
        TestData.MyName = "Imdadhusen";
   }
}

4. I click on submit button, my custom validation getting fired and here i couldn't able to get value of TestData.MyName. it will display Null instead of Imdadhusen.

Any Answer, Suggestion or Comment highly appreciated!

Thanks, Imdadhusen

来源:https://stackoverflow.com/questions/9667931/static-class-property-getting-null-when-custom-validation-fired-in-silverlight-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!