1:ViewModel 实现验证接口 IDataErrorInfo

WPF常规表单验证

2:实现接口的相关验证逻辑,并把错误信息反馈给 Error

        public string this[string columnName]
        {
            get
            {
                switch (columnName)
                {
                    case "Title":
                        error= string.IsNullOrEmpty(this.Title) ? "主题不能为空" : null;
                        break;
                    case "EmailContent":
                        error = string.IsNullOrEmpty(this.EmailContent) ? "内容不能为空" : null;
                        break;
                }
                return error;
            }
        }

        private string error;
        /// <summary>
        /// 错误信息
        /// </summary>
        public string Error
        {
            get { return error; }
        }

3:保存时验证 Error 是否不为空。

WPF常规表单验证

 

相关文章:

  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2022-01-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-09-27
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案