private void CheckBox_Checked(object sender, RoutedEventArgs e) { var checkBox = e.OriginalSource as CheckBox; Child dataContext = checkBox?.DataContext as Child; if (loadFullTree) { if (dataContext.type == 1) { var item = selectedOutputList.Find(x => x.ECUShortAddress == dataContext.mainBoardShortAddress); if (item == null) { EffectedOutput newOne = new EffectedOutput(); newOne.ECUShortAddress = dataContext.mainBoardShortAddress; newOne.PositiveOutputs.Add(dataContext.Index); selectedOutputList.Add(newOne); } else { item.PositiveOutputs.Add(dataContext.Index); } } else if (dataContext.type == 2) { var item = selectedOutputList.Find(x => x.ECUShortAddress == dataContext.mainBoardShortAddress); if (item == null) { EffectedOutput newOne = new EffectedOutput(); newOne.ECUShortAddress = dataContext.mainBoardShortAddress; newOne.NegativeOutputs.Add(dataContext.Index); selectedOutputList.Add(newOne); } else { item.NegativeOutputs.Add(dataContext.Index); } } } else { if (dataContext.type == 1) { selectedOutputs.PositiveOutputs.Add(dataContext.Index); } else if (dataContext.type == 2) { selectedOutputs.NegativeOutputs.Add(dataContext.Index); } } }
public void draw(ECU ecu, EffectedOutput selectedOutputs) { this.ecu = ecu; this.selectedOutputs = selectedOutputs; loadFullTree = false; ObservableCollection <Child> positiveOutputs = new ObservableCollection <Child>(); ObservableCollection <Child> negativeOutputs = new ObservableCollection <Child>(); foreach (PositiveOutput item in ecu.positiveList) { Child child = new Child(); child.Title = item.Header.ToString(); child.Index = item.Index; child.mainBoardShortAddress = ecu.shortAddress; child.CheckedVisible = true; child.type = 1; child.Checked = selectedOutputs.PositiveOutputs.Any(x => x == child.Index); positiveOutputs.Add(child); } foreach (NegativeOutput item in ecu.negativeList) { Child child = new Child(); child.Title = item.Header.ToString(); child.Index = item.Index; child.mainBoardShortAddress = ecu.shortAddress; child.CheckedVisible = true; child.Checked = selectedOutputs.NegativeOutputs.Any(x => x == child.Index); child.type = 2; negativeOutputs.Add(child); } Child positive = new Child(); positive.Title = "Positive Outputs"; positive.CheckedVisible = false; positive.Children = positiveOutputs; Child negative = new Child(); negative.Title = "Negative Outputs"; negative.CheckedVisible = false; negative.Children = negativeOutputs; root.Add(positive); root.Add(negative); }