private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (HandlingSelectionChange) { return; } HandlingSelectionChange = true; var cb = sender as ComboBox; //if (cb.SelectedItem is the VM with Style != Normal) ClockGroupVM foundVM = null; foreach (ClockGroupVM vm in Clocks.Model.GroupsVM.VMs) { if (vm.FontStyle != FontStyles.Normal && ReferenceEquals(cb.SelectedItem, vm)) { foundVM = vm; break; } } if (foundVM != null) { cb.Text = ""; cb.SelectedValue = null; e.Handled = true; } HandlingSelectionChange = false; }
private void ComboBox_PreviewKeyDown(object sender, KeyEventArgs e) { var cb = sender as ComboBox; if ((e.Key == Key.Return || e.Key == Key.Enter) && cb.Text != "") { bool duplicate = false; foreach (ClockGroupVM vm in Clocks.Model.GroupsVM.VMs) { if (vm.Name == cb.Text) { cb.SelectedItem = vm; duplicate = true; break; } } if (duplicate) { return; } // create a ClockGroupM and corresponding ClockGroupVM // (ClockGroupVM inherits from ClockGroupM) var cvm = new ClockGroupVM(new ClockGroupM() { Name = cb.Text }); Clocks.Model.GroupsVM.VMs.Insert(0, cvm); cb.SelectedItem = cvm; } }
public FilterM ClockGroupVMToFilterM(ClockGroupVM vm) { var f = new FilterM(MyClocks.MyDataFile.ClockVMCollection.Model, $"{MyClocks.GroupsVM.VMs.IndexOf(vm) + 1}") { ShowActive = true, ShowInactive = true, ShowAlarms = true, ShowTimers = true }; return(f); }
public static bool ClockGroupVMEqualsWithinTargetToFilterM(ClockGroupVM vm, FilterM m) { return(m.GroupNames.Count > 0 && m.ShowsGroup(vm.Name)); }
private void MyModel_Ms_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (!SynchDisabled3) { SynchDisabled3 = true; Utils.SynchronizeCollectionChange(MyModel.Ms, e, VMs, afterAddition: null, prepareDeletion: null, equalsWithinTargetTo: new Func <FilterM, FilterVM, bool>((FilterM m, FilterVM vm) => { return(vm.MyFilter == m); }), toTarget: new Func <FilterM, FilterVM>((FilterM m) => { return(new FilterVM() { DisplayString = m.GroupNames[0], // TODO: what if there are more groups in the filter? MyFilter = m, MyEmptyImageSource = new BitmapImage( new Uri("/Resources/pictograma folder 2.png", UriKind.Relative)), MyNonEmptyImageSource = new BitmapImage( new Uri("/Resources/pictograma folder cu continut.png", UriKind.Relative)) }); })); SynchDisabled3 = false; } if (!SynchDisabled2) { SynchDisabled2 = true; Utils.SynchronizeCollectionChange(MyModel.Ms, e, MyClocks.GroupsVM.VMs, afterAddition: null, prepareDeletion: null, equalsWithinTargetTo: new Func <FilterM, ClockGroupVM, bool>((FilterM fm, ClockGroupVM gm) => { return(fm.SearchString == gm.Name); }), toTarget: new Func <FilterM, ClockGroupVM>((FilterM m) => { if (m.GroupNames.Count == 0) { return(null); } //return new FilterVM() //{ // //DisplayString = m. // MyFilter = m //}; var gm = new ClockGroupVM() { DisplayString = m.GroupNames[0], Name = m.GroupNames[0] }; //var f = new FilterM(MyClocks.MyDataFile.ClockVMCollection.Model, // $"{MyModel.Ms.IndexOf(m) + 1}") //{ // ShowActive = true, // ShowInactive = true, // ShowAlarms = true, // ShowTimers = true //}; return(gm); }), startingIndexInSource: 5, startingIndexInTarget: 0); SynchDisabled2 = false; } }