using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; using System.Linq; using Plume.Interfaces.Settings; using Plume.WPF.Mvvm; namespace JD.Remoting.WPF.Module.Settings { public class RemotingSettings : BindableBase, ISettings { public RemotingSettings() { Connections.CollectionChanged += ConnectionsOnCollectionChanged; foreach (var connection in Connections) { connection.PropertyChanged += ConnectionOnPropertyChanged; } } private void ConnectionsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { OnPropertyChanged(nameof(Connections)); if (e.NewItems != null) { foreach (var engineConnection in e.NewItems.Cast()) { engineConnection.PropertyChanged += ConnectionOnPropertyChanged; } } if (e.OldItems != null) { foreach (var engineConnection in e.OldItems.Cast()) { engineConnection.PropertyChanged -= ConnectionOnPropertyChanged; } } } private void ConnectionOnPropertyChanged(object sender, PropertyChangedEventArgs e) { OnPropertyChanged(nameof(Connections)); } public ObservableCollection Connections { get; set; } = new ObservableCollection(); } }