CalendarDatePickerDateValidationErrorEventArgs.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // (c) Copyright Microsoft Corporation.
  2. // This source is subject to the Microsoft Public License (Ms-PL).
  3. // Please see https://go.microsoft.com/fwlink/?LinkID=131993 for details.
  4. // All other rights reserved.
  5. using System;
  6. namespace Avalonia.Controls
  7. {
  8. /// <summary>
  9. /// Provides data for the
  10. /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
  11. /// event.
  12. /// </summary>
  13. public class CalendarDatePickerDateValidationErrorEventArgs : EventArgs
  14. {
  15. private bool _throwException;
  16. /// <summary>
  17. /// Initializes a new instance of the
  18. /// <see cref="T:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs" />
  19. /// class.
  20. /// </summary>
  21. /// <param name="exception">
  22. /// The initial exception from the
  23. /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
  24. /// event.
  25. /// </param>
  26. /// <param name="text">
  27. /// The text that caused the
  28. /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
  29. /// event.
  30. /// </param>
  31. public CalendarDatePickerDateValidationErrorEventArgs(Exception exception, string text)
  32. {
  33. Text = text;
  34. Exception = exception;
  35. }
  36. /// <summary>
  37. /// Gets the initial exception associated with the
  38. /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
  39. /// event.
  40. /// </summary>
  41. /// <value>
  42. /// The exception associated with the validation failure.
  43. /// </value>
  44. public Exception Exception { get; private set; }
  45. /// <summary>
  46. /// Gets the text that caused the
  47. /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" />
  48. /// event.
  49. /// </summary>
  50. /// <value>
  51. /// The text that caused the validation failure.
  52. /// </value>
  53. public string Text { get; private set; }
  54. /// <summary>
  55. /// Gets or sets a value indicating whether
  56. /// <see cref="P:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs.Exception" />
  57. /// should be thrown.
  58. /// </summary>
  59. /// <value>
  60. /// True if the exception should be thrown; otherwise, false.
  61. /// </value>
  62. /// <exception cref="T:System.ArgumentException">
  63. /// If set to true and
  64. /// <see cref="P:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs.Exception" />
  65. /// is null.
  66. /// </exception>
  67. public bool ThrowException
  68. {
  69. get => _throwException;
  70. set
  71. {
  72. if (value && Exception == null)
  73. {
  74. throw new ArgumentException("Cannot Throw Null Exception");
  75. }
  76. _throwException = value;
  77. }
  78. }
  79. }
  80. }