/// <summary> /// The update models. /// </summary> private void UpdateModels() { WizardItemCollection items = new WizardItemCollection(this.Items.OfType <WizardItem>()); // Remove any models that no longer exist. foreach (WizardItemModel model in this.models.ToList()) { if (!items.Contains(model.Id)) { if (model.Parent != null) { model.Parent.Children.Remove(model); model.Parent = null; } this.models.Remove(model); } } // Set up new models. foreach (WizardItem item in items) { if (item.Model == null) { WizardItemModel model = new WizardItemModel() { BackCommand = this.BackCommand, ForwardCommand = this.ForwardCommand, SelectCommand = this.SelectCommand }; item.Model = model; this.models.Add(model); } } // Update the model tree structure. foreach (WizardItemModel model in this.models) { if (model.ParentId == null) { model.Parent = null; } else { WizardItemModel parent = this.models.First(x => string.Equals(x.Id, model.ParentId)); if (!parent.Children.Contains(model)) { parent.Children.Add(model); } model.Parent = parent; } } }
/// <summary> /// The on wizard item parent changed. /// </summary> /// <param name="sender"> The sender. </param> /// <param name="e"> The event Arguments. </param> protected virtual void OnWizardItemParentChanged(object sender, RoutedEventArgs e) { WizardItem wizardItem = (WizardItem)sender; WizardItemCollection items = new WizardItemCollection(this.Items.OfType <WizardItem>()); WizardItemModel model = wizardItem.Model; WizardItemModel oldParent = wizardItem.Model.Parent; // Disconnect from old parent. if (oldParent != null) { oldParent.Children.Remove(model); model.Parent = null; } // Connect to new parent. if ((wizardItem.ParentId != null) && items.Contains(wizardItem.ParentId)) { WizardItemModel newParent = items[wizardItem.ParentId].Model; newParent.Children.Add(model); model.Parent = newParent; } }