BatchStatus.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace PDF_Office.CustomControl
  16. {
  17. /// <summary>
  18. /// BatchStatus.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class BatchStatus : UserControl
  21. {
  22. public BatchStatus()
  23. {
  24. InitializeComponent();
  25. }
  26. public int MaxStatusValue
  27. {
  28. get { return (int)GetValue(MaxStatusValueProperty); }
  29. set
  30. {
  31. SetValue(MaxStatusValueProperty, value);
  32. }
  33. }
  34. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  35. public static readonly DependencyProperty MaxStatusValueProperty =
  36. DependencyProperty.Register("MaxStatusValue", typeof(int), typeof(BatchStatus), new PropertyMetadata(10));
  37. public string StatusValue
  38. {
  39. get { return (string)GetValue(StatusValueProperty); }
  40. set
  41. {
  42. SetValue(StatusValueProperty, value);
  43. }
  44. }
  45. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  46. public static readonly DependencyProperty StatusValueProperty =
  47. DependencyProperty.Register("StatusValue", typeof(string), typeof(BatchStatus), new PropertyMetadata("wait",
  48. new PropertyChangedCallback(OnPropertyChanged), // 第3个值回调位置
  49. new CoerceValueCallback(OnCoerceValueCallback) // 第2个强制回调位置
  50. )
  51. , new ValidateValueCallback(OnValidateValueCallBack));
  52. static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  53. {
  54. (d as BatchStatus).CalculateProgress(e.NewValue.ToString());
  55. }
  56. static object OnCoerceValueCallback(DependencyObject d, object obj)
  57. {
  58. return obj;
  59. }
  60. static bool OnValidateValueCallBack(object obj)
  61. {
  62. return true;
  63. }
  64. void CalculateProgress(string value)
  65. {
  66. if (value == "wait")
  67. {
  68. this.wait.Visibility = Visibility.Visible;
  69. this.complete.Visibility = Visibility.Hidden;
  70. this.error.Visibility = Visibility.Hidden;
  71. this.progress.Visibility = Visibility.Hidden;
  72. }
  73. if (value == "complete")
  74. {
  75. this.complete.Visibility = Visibility.Visible;
  76. this.wait.Visibility = Visibility.Hidden;
  77. this.error.Visibility = Visibility.Hidden;
  78. this.progress.Visibility = Visibility.Hidden;
  79. }
  80. if (value == "error")
  81. {
  82. this.error.Visibility = Visibility.Visible;
  83. this.wait.Visibility = Visibility.Hidden;
  84. this.complete.Visibility = Visibility.Hidden;
  85. this.progress.Visibility = Visibility.Hidden;
  86. }
  87. if (int.TryParse(value, out _))
  88. {
  89. this.progress.Visibility = Visibility.Visible;
  90. this.wait.Visibility = Visibility.Hidden;
  91. this.complete.Visibility = Visibility.Hidden;
  92. this.error.Visibility = Visibility.Hidden;
  93. double step = (double.Parse(value) / (double)MaxStatusValue) * Math.PI;
  94. progressBar.StrokeDashArray = new DoubleCollection() { step, 10000 };
  95. }
  96. }
  97. }
  98. }