HarewareCompare.xaml.cs 3.8 KB

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