CustomProgressBarControl.xaml.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 static readonly DependencyProperty ProgressBarHeightProperty =
  25. DependencyProperty.Register(nameof(ProgressBarHeight), typeof(double), typeof(CustomProgressBarControl), new PropertyMetadata(5.0));
  26. public double ProgressBarHeight
  27. {
  28. get => (double)GetValue(ProgressBarHeightProperty);
  29. set => SetValue(ProgressBarHeightProperty, value);
  30. }
  31. public CustomProgressBarControl()
  32. {
  33. InitializeComponent();
  34. Grid.DataContext = this;
  35. }
  36. public event PropertyChangedEventHandler PropertyChanged;
  37. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  38. {
  39. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  40. }
  41. protected void UpdateProper<T>(ref T properValue,
  42. T newValue,
  43. [CallerMemberName] string properName = "")
  44. {
  45. if (object.Equals(properValue, newValue))
  46. return;
  47. properValue = newValue;
  48. OnPropertyChanged(properName);
  49. }
  50. }
  51. }