JD2022-TU1/main/tools/modules/JD.Remoting.WPF.Module/Settings/RemotingSettings.cs

49 lines
1.6 KiB
C#

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>())
{
engineConnection.PropertyChanged += ConnectionOnPropertyChanged;
}
}
if (e.OldItems != null)
{
foreach (var engineConnection in e.OldItems.Cast<EngineConnection>())
{
engineConnection.PropertyChanged -= ConnectionOnPropertyChanged;
}
}
}
private void ConnectionOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged(nameof(Connections));
}
public ObservableCollection<EngineConnection> Connections { get; set; } = new ObservableCollection<EngineConnection>();
}
}