using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using GlobalData; using System.Collections.ObjectModel; using System.Windows; namespace ConfigFileManager.ViewModels.Dialog; internal partial class MigrateViewModel : ObservableObject, IDialogAware { public MigrateViewModel(DeviceCollection deviceCollection) { this.Sources = []; foreach (IList deviceInfos in deviceCollection.Devices.Values) this.Sources.AddRange(deviceInfos); } [ObservableProperty] private ObservableCollection _Sources; [ObservableProperty] private DeviceInfo_VM? _Source; public DialogCloseListener RequestClose { get; set; } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { if (!parameters.TryGetValue("Device", out DeviceInfo_VM? deviceInfo) || deviceInfo is null) { MessageBox.Show("Config Device Error"); this.RequestClose.Invoke(); return; } this.Sources.Remove(deviceInfo); this.Source = deviceInfo; } [RelayCommand] private void Close() { this.RequestClose.Invoke(); } }