public override void OnApplyTemplate() { base.OnApplyTemplate(); AddBtn.Command = new RelayCommand(() => { var prot = new ProjectSettingVM<Protection>(proj, new SettingItem<Protection>()); prot.Id = proj.Protections[0].Id; rule.Protections.Add(prot); }); RemoveBtn.Command = new RelayCommand(() => { int selIndex = prots.SelectedIndex; Debug.Assert(selIndex != -1); rule.Protections.RemoveAt(prots.SelectedIndex); prots.SelectedIndex = selIndex >= rule.Protections.Count ? rule.Protections.Count - 1 : selIndex; }, () => prots.SelectedIndex != -1); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); AddBtn.Command = new RelayCommand(() => { var prot = new ProjectSettingVM <Protection>(proj, new SettingItem <Protection>()); prot.Id = proj.Protections[0].Id; rule.Protections.Add(prot); }); RemoveBtn.Command = new RelayCommand(() => { int selIndex = prots.SelectedIndex; Debug.Assert(selIndex != -1); rule.Protections.RemoveAt(prots.SelectedIndex); prots.SelectedIndex = selIndex >= rule.Protections.Count ? rule.Protections.Count - 1 : selIndex; }, () => prots.SelectedIndex != -1); }