/// <summary> /// Look for a shown child and replace it with a new one /// <para>This comes as we have set it up for items to be replaced in the hierarchy</para> /// </summary> /// <param name="shown">Shown item to replace</param> /// <param name="newItem">New item to replace the shown with</param> private void ReplaceShownChild(ListItemVM shown, ListItemVM newItem) { if (ParentItemVM == null) { if (ParentVM != null) { ParentVM.ReplaceSelectedItem(newItem); } } else { if (String.Equals(Model.Code.ChildType, IcdCodeStrings.ChildType_Direct)) { ParentItemVM.ReplaceShownChild(shown, newItem); } else { var newParentChildren = ParentItemVM.Children.ToList(); for (int childOn = 0; childOn < newParentChildren.Count; ++childOn) { if (Object.ReferenceEquals(newParentChildren[childOn], shown) || Object.ReferenceEquals(newParentChildren[childOn], this)) { newParentChildren[childOn] = newItem; } } ParentItemVM.Children = newParentChildren; } } }
/// <summary> /// Replace a single, selected item /// <para>Attempts to propagate to the ListVM of ParentVM or calls ReplaceShownChild when appropriate</para> /// </summary> /// <param name="newItem">New item to replace the single selected item with</param> public void ReplaceSelectedChild(ListItemVM newItem) { if (newItem == null) { return; } if (ParentItemVM == null) { if (ParentVM != null) { ParentVM.ReplaceSelectedItem(newItem); } } else { ReplaceShownChild(this, newItem); } }
/// <summary> /// Attempt to clear the ParentVM ListVM when appropriate. /// <para>Will figure if needs to load </para> /// </summary> public void ClearForParent() { if (String.Equals(Model.Code.ChildType, IcdCodeStrings.ChildType_Direct)) { if ((ParentVM != null) && (ParentItemVM != null)) { ParentItemVM.ClearToAllChildren(); if (Object.ReferenceEquals(ParentVM.Items.Items[0], this)) { ParentVM.ReplaceSelectedItem(ParentItemVM, false); } else { ReplaceShownChild(this, ParentItemVM); } } else if (ParentVM != null) { ParentVM.ClearToFullList(); } } }