private void HandleDeviceDeleted(IDeviceInfo deviceInfo) { if (SelectedDevice.Value == deviceInfo) { var noDevice = availableDevices.Single(x => x.Info == null); SelectedDevice.SetValue(noDevice); } var deviceViewModel = availableDevices.Single(x => x.Info == deviceInfo); availableDevices.Remove(deviceViewModel); }
public MainWindowViewModel( IMainWindow mainWindowView, IDeviceManager deviceManager, IDispatcher dispatcher) { this.deviceManager = deviceManager; this.dispatcher = dispatcher; availableDevices = new ObservableCollection <DeviceViewModel>(); var noDeviceViewModel = new DeviceViewModel("-", null); availableDevices.Add(noDeviceViewModel); AvailableDevices = new ReadOnlyObservableCollection <DeviceViewModel>(availableDevices); SelectedDevice.SetValue(noDeviceViewModel); SelectedDevice.ValueChanged.Subscribe(HandleDeviceChanged); receivedMessages = new ObservableCollection <MessageViewModel>(); ReceivedMessages = new ReadOnlyObservableCollection <MessageViewModel>(receivedMessages); deviceManager.DeviceAdded.Subscribe(HandleDeviceAdded); deviceManager.DeviceDeleted.Subscribe(HandleDeviceDeleted); pressedPedals = new ObservableCollection <OnOffIndicatorViewModel>(); PressedPedals = new ReadOnlyObservableCollection <OnOffIndicatorViewModel>(pressedPedals); for (var i = 0; i < 8 * sizeof(uint); i++) { pressedPedals.Add(new OnOffIndicatorViewModel(i + 1, false)); } playedNotes = new ObservableCollection <OnOffIndicatorViewModel>(); PlayedNotes = new ReadOnlyObservableCollection <OnOffIndicatorViewModel>(playedNotes); for (var i = 0; i < 8 * sizeof(uint); i++) { playedNotes.Add(new OnOffIndicatorViewModel(i + 1, false)); } pedalPins = new ObservableCollection <OnOffIndicatorViewModel>(); PedalPins = new ReadOnlyObservableCollection <OnOffIndicatorViewModel>(pedalPins); for (var i = 0; i < 8 * sizeof(uint); i++) { pedalPins.Add(new OnOffIndicatorViewModel(0, false)); } EditCommand = new ManualCommand(HandleEditCommand, true); ApplyCommand = new ManualCommand(HandleApplyCommand, false); IsEditingConfiguration.SetValue(false); mainWindowView.DataContext = this; }
public MainWindowViewModel() { availableDevices = new ObservableCollection <DeviceViewModel>(); var dummyDevice = new DeviceViewModel("COM1", null); availableDevices.Add(dummyDevice); AvailableDevices = new ReadOnlyObservableCollection <DeviceViewModel>(availableDevices); SelectedDevice.SetValue(dummyDevice); receivedMessages = new ObservableCollection <MessageViewModel>(); receivedMessages.Add(new MessageViewModel("A")); receivedMessages.Add(new MessageViewModel("B")); receivedMessages.Add(new MessageViewModel("C")); ReceivedMessages = new ReadOnlyObservableCollection <MessageViewModel>(receivedMessages); pressedPedals = new ObservableCollection <OnOffIndicatorViewModel>(); PressedPedals = new ReadOnlyObservableCollection <OnOffIndicatorViewModel>(pressedPedals); for (var i = 0; i < 8 * sizeof(uint); i++) { pressedPedals.Add(new OnOffIndicatorViewModel(i + 1, i % 2 != 0)); } playedNotes = new ObservableCollection <OnOffIndicatorViewModel>(); PlayedNotes = new ReadOnlyObservableCollection <OnOffIndicatorViewModel>(playedNotes); for (var i = 0; i < 8 * sizeof(uint); i++) { playedNotes.Add(new OnOffIndicatorViewModel(i + 1, i % 2 == 0)); } FirstNote.SetValue(40); Velocity.SetValue(70); DebouncingTime.SetValue(125); pedalPins = new ObservableCollection <OnOffIndicatorViewModel>(); PedalPins = new ReadOnlyObservableCollection <OnOffIndicatorViewModel>(pedalPins); for (var i = 0; i < 8 * sizeof(uint); i++) { pedalPins.Add(new OnOffIndicatorViewModel(i + 1, false)); } EditCommand = new ManualCommand(HandleEditCommand, true); ApplyCommand = new ManualCommand(HandleApplyCommand, false); IsEditingConfiguration.SetValue(true); }