Beispiel #1
0
        /// <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;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// The can forward.
        /// </summary>
        /// <returns> The <see cref="bool"/>. </returns>
        private bool CanForward()
        {
            bool canForward = false;

            WizardItemModel selectedModel = this.SelectedModel;

            if ((selectedModel != null) && (selectedModel.Children.Count > 0) && selectedModel.IsForwardEnabled)
            {
                canForward = true;
            }

            return(canForward);
        }
Beispiel #3
0
        /// <summary>
        /// The can back.
        /// </summary>
        /// <returns> The <see cref="bool"/>. </returns>
        private bool CanBack()
        {
            bool canback = false;

            WizardItemModel selectedModel = this.SelectedModel;

            if ((selectedModel != null) && (selectedModel.Parent != null) && selectedModel.IsBackwardEnabled)
            {
                canback = true;
            }

            return(canback);
        }
Beispiel #4
0
        /// <summary>
        /// The can back allowed.
        /// </summary>
        /// <returns> The <see cref="bool"/>. </returns>
        private bool CanBackAllowed()
        {
            bool canback = false;

            WizardItemModel selectedModel = this.SelectedModel;

            if ((selectedModel != null) && (selectedModel.Parent != null))
            {
                canback = true;
            }

            return(canback);
        }
Beispiel #5
0
        /// <summary>
        /// The select.
        /// </summary>
        /// <param name="parameter"> The parameter. </param>
        private void Select(object parameter)
        {
            WizardItemModel model = this.GetModel(parameter);

            if (model != null)
            {
                if (this.DisplayItem != null)
                {
                    WizardItemModel displayModel = this.DisplayItem.Model;
                    if (displayModel != null)
                    {
                        if (this.Breadcrumb.Contains(model))
                        {
                            // Going back through the breadcrumb.
                            this.IsNavigatingBackward = true;
                        }
                        else if (this.Breadcrumb
                                 .Traverse(x => x.Children)
                                 .Where(x => x != this.Breadcrumb.Last() && !this.Breadcrumb.Last().Children.Traverse(y => y.Children).Contains(x))
                                 .Any(x => x.Equals(model)))
                        {
                            // Going sideways through the breadcrumb.
                            this.IsNavigatingHorizontally = true;
                        }
                        else
                        {
                            // Go forward with the breadcrumb.
                            this.IsNavigatingForward = true;
                        }
                    }
                }

                WizardItem newItem = this.GetItem(model);
                this.SetSelectedItemIfCanNavigate(newItem);
            }
        }
Beispiel #6
0
        /// <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;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets a <see cref="WizardItemModel"/> from the specified object which can be a <see cref="WizardItemModel"/>, <see cref="WizardItem"/> or wizard item ID.
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        /// <returns>The <see cref="WizardItemModel"/>.</returns>
        private WizardItemModel GetModel(object parameter)
        {
            WizardItemModel model = parameter as WizardItemModel;

            if (model == null)
            {
                WizardItem wizardItem = parameter as WizardItem;
                if (wizardItem != null)
                {
                    model = wizardItem.Model;
                }
            }

            if (model == null)
            {
                string wizardItemId = parameter as string;
                if (wizardItemId != null)
                {
                    model = this.models.FirstOrDefault(x => string.Equals(x.Id, wizardItemId, StringComparison.Ordinal));
                }
            }

            return(model);
        }
Beispiel #8
0
        /// <summary>
        /// The update to model.
        /// </summary>
        /// <param name="model"> The model. </param>
        private void UpdateToModel(WizardItemModel model)
        {
            if (model != null && !this.isUpdating)
            {
                this.isUpdating = true;

                model.Description       = this.Description;
                model.Icon              = this.Icon;
                model.IconTemplate      = this.IconTemplate;
                model.Id                = this.Id;
                model.IsBackwardEnabled = this.IsBackwardEnabled;
                model.IsEntering        = this.IsEntering;
                model.IsForwardEnabled  = this.IsForwardEnabled;
                model.IsLeaving         = this.IsLeaving;
                model.IsSelected        = this.IsSelected;
                model.IsVisited         = this.IsVisited;
                model.ParentId          = this.ParentId;
                model.ShortTitle        = this.ShortTitle;
                model.Title             = this.Title;
                model.Visibility        = this.Visibility;

                this.isUpdating = false;
            }
        }
Beispiel #9
0
        /// <summary>
        /// The can select.
        /// </summary>
        /// <param name="parameter"> The parameter. </param>
        /// <returns> The <see cref="bool"/>. </returns>
        private bool CanSelect(object parameter)
        {
            WizardItemModel model = this.GetModel(parameter);

            return((model != null) && (this.SelectedItem != this.GetItem(model)));
        }
Beispiel #10
0
 /// <summary>
 /// The get item.
 /// </summary>
 /// <param name="model"> The model. </param>
 /// <returns> The <see cref="WizardItem"/>. </returns>
 private WizardItem GetItem(WizardItemModel model)
 {
     return(this.Items.OfType <WizardItem>().FirstOrDefault(x => string.Equals(x.Id, model.Id, StringComparison.Ordinal)));
 }
Beispiel #11
0
        /// <summary>
        /// The update breadcrumb.
        /// </summary>
        private void UpdateBreadcrumb()
        {
            WizardItemModel selectedModel = this.SelectedModel;

            if (selectedModel != null)
            {
                if (this.Breadcrumb.Contains(selectedModel))
                {
                    // Going back through the breadcrumb.
                    for (WizardItemModel lastModel = this.Breadcrumb.Last();
                         !lastModel.Equals(selectedModel);
                         lastModel = this.Breadcrumb.Last())
                    {
                        lastModel.IsVisited = false;
                        this.Breadcrumb.Remove(lastModel);
                    }
                }
                else if (this.Breadcrumb
                         .Traverse(x => x.Children)
                         .Where(x => x != this.Breadcrumb.Last() && !this.Breadcrumb.Last().Children.Traverse(y => y.Children).Contains(x))
                         .Any(x => x.Equals(selectedModel)))
                {
                    // Going sideways through the breadcrumb.
                    List <WizardItemModel> newBreadcrumb = new List <WizardItemModel>();
                    for (WizardItemModel parent = selectedModel.Parent; parent != null; parent = parent.Parent)
                    {
                        newBreadcrumb.Add(parent);
                    }

                    newBreadcrumb.Reverse();
                    newBreadcrumb.Add(selectedModel);

                    for (int i = 0; i < newBreadcrumb.Count; ++i)
                    {
                        WizardItemModel newModel = newBreadcrumb[i];

                        if ((i >= this.Breadcrumb.Count) || !this.Breadcrumb[i].Equals(newModel))
                        {
                            while (i < this.Breadcrumb.Count)
                            {
                                WizardItemModel oldLastModel = this.Breadcrumb.Last();
                                oldLastModel.IsVisited = false;
                                this.Breadcrumb.Remove(oldLastModel);
                            }

                            newModel.IsVisited = true;
                            this.Breadcrumb.Add(newModel);
                        }
                    }
                }
                else
                {
                    // Go forward with the breadcrumb.
                    if (!this.Breadcrumb.Contains(selectedModel))
                    {
                        selectedModel.IsVisited = true;

                        // If skipping a few pages to go ahead, add the in-between bread crumb items.
                        List <WizardItemModel> inBetweenModels = new List <WizardItemModel>();
                        for (WizardItemModel parent = selectedModel.Parent; parent != null; parent = parent.Parent)
                        {
                            if (!this.Breadcrumb.Contains(parent))
                            {
                                parent.IsVisited = true;
                                inBetweenModels.Add(parent);
                            }
                            else
                            {
                                break;
                            }
                        }

                        inBetweenModels.Reverse();
                        this.Breadcrumb.AddRange(inBetweenModels);

                        this.Breadcrumb.Add(selectedModel);
                    }
                }

                for (int i = 0; i < this.Breadcrumb.Count; ++i)
                {
                    WizardItemModel model = this.Breadcrumb[i];

                    // Select last breadcrumb.
                    model.IsSelected = i == (this.Breadcrumb.Count - 1);
                }
            }
        }