Пример #1
0
 protected virtual void ClearSubViewModel()
 {
     foreach (var subVMItem in SubVMItemsCollection)
     {
         SubViewModelEventsUnregister(subVMItem);
         if (IsSubVMNeedDispose && subVMItem is IDisposable disposableItem)
         {
             disposableItem.Dispose();
         }
     }
     _model2VMDic.Clear();
     SubVMItemsCollection.Clear();
 }
Пример #2
0
 protected virtual void RemoveSubViewModel(TSubM subModelItem)
 {
     if (_model2VMDic.ContainsKey(subModelItem))
     {
         var oldSubVMItem = _model2VMDic[subModelItem];
         SubViewModelEventsUnregister(oldSubVMItem);
         SubVMItemsCollection.Remove(oldSubVMItem);
         _model2VMDic.Remove(subModelItem);
         if (IsSubVMNeedDispose && oldSubVMItem is IDisposable disposableItem)
         {
             disposableItem.Dispose();
         }
     }
     //else
     //    throw new Exception("Can't find the related sub ViewModel object.");
 }
Пример #3
0
        protected virtual void ReplaceSubViewModel(TSubM oldSubModelItem, TSubM newSubModelItem, int index)
        {
            if (_model2VMDic.ContainsKey(oldSubModelItem))
            {
                var oldSubVMItem = _model2VMDic[oldSubModelItem];
                SubViewModelEventsUnregister(oldSubVMItem);
                _model2VMDic.Remove(oldSubModelItem);
                if (IsSubVMNeedDispose && oldSubVMItem is IDisposable disposableItem)
                {
                    disposableItem.Dispose();
                }

                var newSubVMItem = GetSubViewModelInstance(newSubModelItem);
                SubViewModelEventsRegister(newSubVMItem);
                _model2VMDic[newSubModelItem] = newSubVMItem;
                SubVMItemsCollection.Add(newSubVMItem);
            }
            //else
            //    throw new Exception("The sub VM object related to oldSubModelItem dose not exist.");
        }
Пример #4
0
 protected virtual void MoveSubViewModel(int oldIndex, int newIndex)
 {
     SubVMItemsCollection.Move(oldIndex, newIndex);
 }