HarewareCompare.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using GlobalData;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using System.Windows.Media;
  6. namespace ConfigFileManager.Controls;
  7. public partial class HarewareCompare : UserControl
  8. {
  9. public HarewareCompare()
  10. {
  11. InitializeComponent();
  12. }
  13. public DeviceInfo_VM Source
  14. {
  15. get { return (DeviceInfo_VM)GetValue(SourceProperty); }
  16. set { SetValue(SourceProperty, value); }
  17. }
  18. public static readonly DependencyProperty SourceProperty =
  19. DependencyProperty.Register("Source", typeof(DeviceInfo_VM), typeof(HarewareCompare), new PropertyMetadata(default, PropertyChangedCallback));
  20. public DeviceInfo_VM Target
  21. {
  22. get { return (DeviceInfo_VM)GetValue(TargetProperty); }
  23. set { SetValue(TargetProperty, value); }
  24. }
  25. public static readonly DependencyProperty TargetProperty =
  26. DependencyProperty.Register("Target", typeof(DeviceInfo_VM), typeof(HarewareCompare), new PropertyMetadata(default, PropertyChangedCallback));
  27. private static readonly ImageSource normal = (ImageSource)Application.Current.Resources["Icon_finish"];
  28. private static readonly ImageSource warning = (ImageSource)Application.Current.Resources["Icon_Error"];
  29. private static readonly ImageSource fatal = (ImageSource)Application.Current.Resources["Icon_Fatal"];
  30. private static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  31. {
  32. if (d is not HarewareCompare compare)
  33. return;
  34. if (compare.Source is null || compare.Target is null)
  35. return;
  36. if (compare.Source.DeviceModel != compare.Target.DeviceModel)
  37. {
  38. compare.DeviceModelImage.Source = fatal;
  39. compare.DeviceSubModelImage.Source = fatal;
  40. compare.SoftwareVersionImage.Source = fatal;
  41. compare.Migrate.IsEnabled = false;
  42. return;
  43. }
  44. if (compare.Source.DeviceSubModel != compare.Target.DeviceSubModel)
  45. {
  46. compare.DeviceModelImage.Source = normal;
  47. compare.DeviceSubModelImage.Source = fatal;
  48. compare.SoftwareVersionImage.Source = fatal;
  49. compare.Migrate.IsEnabled = false;
  50. return;
  51. }
  52. compare.Migrate.IsEnabled = true;
  53. if (compare.Source.SoftwareVersion != compare.Target.SoftwareVersion)
  54. {
  55. compare.DeviceModelImage.Source = normal;
  56. compare.DeviceSubModelImage.Source = normal;
  57. compare.SoftwareVersionImage.Source = warning;
  58. return;
  59. }
  60. compare.DeviceModelImage.Source = normal;
  61. compare.DeviceSubModelImage.Source = normal;
  62. compare.SoftwareVersionImage.Source = normal;
  63. }
  64. public ICommand MigrateCommand
  65. {
  66. get { return (ICommand)GetValue(MigrateCommandProperty); }
  67. set { SetValue(MigrateCommandProperty, value); }
  68. }
  69. // Using a DependencyProperty as the backing store for MigrateCommand. This enables animation, styling, binding, etc...
  70. public static readonly DependencyProperty MigrateCommandProperty =
  71. DependencyProperty.Register("MigrateCommand", typeof(ICommand), typeof(HarewareCompare), new PropertyMetadata(default));
  72. }