ShowMessage.xaml.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  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.Navigation;
  16. using System.Windows.Shapes;
  17. namespace TeamAAS_VP.Controls
  18. {
  19. /// <summary>
  20. /// ShowMessage.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class ShowMessage : UserControl, INotifyPropertyChanged
  23. {
  24. public ShowMessage(string title,string message,bool cancel=true)
  25. {
  26. InitializeComponent();
  27. DataContext = this;
  28. Title = title;
  29. Message = message;
  30. IsCancel = cancel;
  31. }
  32. private string _Title;
  33. public string Title
  34. {
  35. get { return _Title; }
  36. set { SetProperty(ref _Title, value); }
  37. }
  38. private string _Message;
  39. public string Message
  40. {
  41. get { return _Message; }
  42. set { SetProperty(ref _Message, value); }
  43. }
  44. private bool _IsCancel;
  45. public bool IsCancel
  46. {
  47. get { return _IsCancel; }
  48. set { SetProperty(ref _IsCancel, value); }
  49. }
  50. #region 属性通知
  51. /// <summary>
  52. /// Occurs when a property value changes.
  53. /// </summary>
  54. public event PropertyChangedEventHandler PropertyChanged;
  55. /// <summary>
  56. /// Checks if a property already matches a desired value. Sets the property and
  57. /// notifies listeners only when necessary.
  58. /// </summary>
  59. /// <typeparam name="T">Type of the property.</typeparam>
  60. /// <param name="storage">Reference to a property with both getter and setter.</param>
  61. /// <param name="value">Desired value for the property.</param>
  62. /// <param name="propertyName">Name of the property used to notify listeners. This
  63. /// value is optional and can be provided automatically when invoked from compilers that
  64. /// support CallerMemberName.</param>
  65. /// <returns>True if the value was changed, false if the existing value matched the
  66. /// desired value.</returns>
  67. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  68. {
  69. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  70. storage = value;
  71. RaisePropertyChanged(propertyName);
  72. return true;
  73. }
  74. /// <summary>
  75. /// Checks if a property already matches a desired value. Sets the property and
  76. /// notifies listeners only when necessary.
  77. /// </summary>
  78. /// <typeparam name="T">Type of the property.</typeparam>
  79. /// <param name="storage">Reference to a property with both getter and setter.</param>
  80. /// <param name="value">Desired value for the property.</param>
  81. /// <param name="propertyName">Name of the property used to notify listeners. This
  82. /// value is optional and can be provided automatically when invoked from compilers that
  83. /// support CallerMemberName.</param>
  84. /// <param name="onChanged">Action that is called after the property value has been changed.</param>
  85. /// <returns>True if the value was changed, false if the existing value matched the
  86. /// desired value.</returns>
  87. protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
  88. {
  89. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  90. storage = value;
  91. onChanged?.Invoke();
  92. RaisePropertyChanged(propertyName);
  93. return true;
  94. }
  95. /// <summary>
  96. /// Raises this object's PropertyChanged event.
  97. /// </summary>
  98. /// <param name="propertyName">Name of the property used to notify listeners. This
  99. /// value is optional and can be provided automatically when invoked from compilers
  100. /// that support <see cref="CallerMemberNameAttribute"/>.</param>
  101. protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
  102. {
  103. OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
  104. }
  105. /// <summary>
  106. /// Raises this object's PropertyChanged event.
  107. /// </summary>
  108. /// <param name="args">The PropertyChangedEventArgs</param>
  109. protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
  110. {
  111. PropertyChanged?.Invoke(this, args);
  112. }
  113. #endregion
  114. }
  115. }