WinValidation.xaml.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Linq.Expressions;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. using FWindSoft.Wpf;
  17. namespace Test.ValidateRule
  18. {
  19. /// <summary>
  20. /// WinValidation.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class WinValidation : Window, INotifyPropertyChanged
  23. {
  24. public WinValidation()
  25. {
  26. InitializeComponent();
  27. MethodExe = (v) => { return false; };
  28. this.DataContext = this;
  29. NameItem = "ff";
  30. this.HasError();
  31. }
  32. public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
  33. /// <summary>
  34. /// 提交变更
  35. /// </summary>
  36. /// <param name="propertyName">变更属性名称</param>
  37. protected void RaisePropertyChanged(String propertyName = "")
  38. {
  39. if (PropertyChanged != null)
  40. {
  41. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  42. }
  43. }
  44. protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression)
  45. {
  46. if (null != propertyExpression)
  47. {
  48. var memberExpression = propertyExpression.Body as MemberExpression;
  49. if (memberExpression != null)
  50. if (this.PropertyChanged != null)
  51. {
  52. this.PropertyChanged(this, new PropertyChangedEventArgs(memberExpression.Member.Name));
  53. }
  54. }
  55. else
  56. {
  57. throw new Exception();
  58. }
  59. }
  60. private string m_Name;
  61. /// <summary>
  62. /// 注释
  63. /// </summary>
  64. public string NameItem
  65. {
  66. get { return this.m_Name; }
  67. set
  68. {
  69. this.m_Name = value;
  70. RaisePropertyChanged(() => this.Name);
  71. }
  72. }
  73. public Func<object,bool> MethodExe { get; set; }
  74. }
  75. }