public AutocompleteViewModel(SuggestionsMaker sugMaker, IEnumerable <object> initItems = null) { Contract.Requires(sugMaker != null); this.sugMaker = sugMaker; this.blankSetter = new BlankSetter(sugMaker.FirstMatchingOrNewWord, OpenMeasureEditor, OpenIcdSelector); this.tagsWritable = new ObservableCollection <TagViewModel>(); Suggestions = new ObservableCollection <SuggestionViewModel>(); Tags = new INCCReadOnlyObservableCollection <TagViewModel>(tagsWritable); Tags.CollectionChangedWrapper += (s, e) => { if (inDispose) { return; } // logger.DebugFormat("{0} '{1}' '{2}'", e.Action, e.OldStartingIndex, e.NewStartingIndex); // кроме добавления пустого тега if (!(e.Action == NotifyCollectionChangedAction.Add && ((TagViewModel)e.NewItems[0]).State == State.Init)) { OnEntitiesChanged(); OnPropertyChanged(() => IsEmpty); } }; DropHandler = new AutocompleteViewModel.DropTargetHandler(this); DragHandler = new AutocompleteViewModel.DragSourceHandler(this); IsDropTargetEnabled = true; IsDragSourceEnabled = true; }
public HealthRecordManager(IHrsHolder holder, PropertyChangedEventHandler onHrVmPropChanged) { this.holder = holder; this.onHrVmPropChanged = onHrVmPropChanged; holder.HealthRecordsChanged += holder_HealthRecordsChanged; var hrs = holder.HealthRecords .OrderBy(hr => hr.Ord) .ToList(); for (int i = 0; i < hrs.Count; i++) { hrs[i].Ord = i; } // all hrs with different order now var hrVMs = hrs .Select(hr => CreateViewModel(hr)) .ToList(); inner = new ObservableCollection <ShortHealthRecordViewModel>(hrVMs); healthRecords = new ObservableCollection <ShortHealthRecordViewModel>(hrVMs .Where(hr => !hr.IsDeleted)); deletedHealthRecords = new ObservableCollection <ShortHealthRecordViewModel>(hrVMs .Where(hr => hr.IsDeleted)); HealthRecords = new INCCReadOnlyObservableCollection <ShortHealthRecordViewModel>(healthRecords); DeletedHealthRecords = new INCCReadOnlyObservableCollection <ShortHealthRecordViewModel>(deletedHealthRecords); inner.CollectionChanged += (s, e) => { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { foreach (ShortHealthRecordViewModel vm in e.NewItems) { healthRecords.Add(vm); } } else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove) { foreach (ShortHealthRecordViewModel vm in e.OldItems) { healthRecords.Remove(vm); deletedHealthRecords.Remove(vm); } } }; }