MigrateViewModel.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using CommunityToolkit.Mvvm.Input;
  3. using GlobalData;
  4. using System.Collections.ObjectModel;
  5. using System.Windows;
  6. namespace ConfigFileManager.ViewModels.Dialog;
  7. internal partial class MigrateViewModel : ObservableObject, IDialogAware
  8. {
  9. public MigrateViewModel(DeviceCollection deviceCollection)
  10. {
  11. this.Sources = [];
  12. foreach (IList<DeviceInfo_VM> deviceInfos in deviceCollection.Devices.Values)
  13. this.Sources.AddRange(deviceInfos);
  14. }
  15. [ObservableProperty]
  16. private ObservableCollection<DeviceInfo_VM> _Sources;
  17. [ObservableProperty]
  18. private DeviceInfo_VM? _Source;
  19. public DialogCloseListener RequestClose { get; set; }
  20. public bool CanCloseDialog()
  21. {
  22. return true;
  23. }
  24. public void OnDialogClosed()
  25. {
  26. }
  27. public void OnDialogOpened(IDialogParameters parameters)
  28. {
  29. if (!parameters.TryGetValue("Device", out DeviceInfo_VM? deviceInfo) || deviceInfo is null)
  30. {
  31. MessageBox.Show("Config Device Error");
  32. this.RequestClose.Invoke();
  33. return;
  34. }
  35. this.Sources.Remove(deviceInfo);
  36. this.Source = deviceInfo;
  37. }
  38. [RelayCommand]
  39. private void Close()
  40. {
  41. this.RequestClose.Invoke();
  42. }
  43. }