public MainWindow() { PollSaveDataParallelArrays pollDataPArray = Settings.Default.PollData; for (var i = 0; i < pollDataPArray.Name.Length; i++) { PollDataCollection.Add(new PollData { PollCommand = pollDataPArray.PollCommand[i], IsPolling = pollDataPArray.IsPolling[i], Name = pollDataPArray.Name[i] }); } individualPollInterval = IndividualPollInterval = Settings.Default.IndividualPollInterval; DependencyPropertyDescriptor.FromProperty(IndividualPollIntervalProperty, typeof(MainWindow)) .AddValueChanged(this, (_, a) => individualPollInterval = IndividualPollInterval); InitializeComponent(); ComCommandSaveDataParallelArrays cmdSavePArray = Settings.Default.ComCommands; for (var i = 0; i < cmdSavePArray.Title.Length; i++) { ComCommandsPanel.Children.Add(InitComCommand(new ComCommand { Title = cmdSavePArray.Title[i], Command = cmdSavePArray.Command[i] })); } DependencyPropertyDescriptor isPollingPropdpDesc = DependencyPropertyDescriptor.FromProperty(PollData.IsPollingProperty, typeof(PollData)); void PollDataIsPollingChanged(object _, EventArgs __) => OnPropertyChanged(nameof(AreAllPolling)); foreach (PollData pollData in PollDataCollection) { isPollingPropdpDesc.AddValueChanged(pollData, PollDataIsPollingChanged); } PollDataCollection.CollectionChanged += (sender, args) => { if ((args.Action == NotifyCollectionChangedAction.Remove) || (args.Action == NotifyCollectionChangedAction.Replace) || (args.Action == NotifyCollectionChangedAction.Reset)) { foreach (PollData pollData in args.OldItems) { isPollingPropdpDesc.RemoveValueChanged(pollData, PollDataIsPollingChanged); pollData.Dispose(); } } if (args.NewItems != null) { foreach (PollData pollData in args.NewItems) { isPollingPropdpDesc.AddValueChanged(pollData, PollDataIsPollingChanged); } } OnPropertyChanged(nameof(AreAllPolling)); }; ComConnection.I.DataReceived += OnComDataReceived; }
private void AddPollDataRow_OnClick(object sender, RoutedEventArgs e) => PollDataCollection.Add(new PollData());