CustomProgressBarControl.xaml.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.Runtime.CompilerServices;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. namespace Compdfkit_Tools.Common
  7. {
  8. public partial class CustomProgressBarControl : UserControl,INotifyPropertyChanged
  9. {
  10. public static readonly DependencyProperty ProgressValueProperty =
  11. DependencyProperty.Register(nameof(ProgressValue), typeof(int), typeof(CustomProgressBarControl), new PropertyMetadata(0));
  12. public int ProgressValue
  13. {
  14. get => (int)GetValue(ProgressValueProperty);
  15. set => SetValue(ProgressValueProperty, value);
  16. }
  17. public static readonly DependencyProperty ProgressMaxValueProperty =
  18. DependencyProperty.Register(nameof(ProgressMaxValue), typeof(int), typeof(CustomProgressBarControl), new PropertyMetadata(100));
  19. public int ProgressMaxValue
  20. {
  21. get => (int)GetValue(ProgressMaxValueProperty);
  22. set => SetValue(ProgressMaxValueProperty, value);
  23. }
  24. public CustomProgressBarControl()
  25. {
  26. InitializeComponent();
  27. Grid.DataContext = this;
  28. }
  29. public event PropertyChangedEventHandler PropertyChanged;
  30. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  31. {
  32. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  33. }
  34. protected void UpdateProper<T>(ref T properValue,
  35. T newValue,
  36. [CallerMemberName] string properName = "")
  37. {
  38. if (object.Equals(properValue, newValue))
  39. return;
  40. properValue = newValue;
  41. OnPropertyChanged(properName);
  42. }
  43. }
  44. }