private IProcedureComponent getBack(IProcedureComponent current)
        {
            if (currentComponent == introductionComponent)
            {
                return(null);
            }
            else if (currentComponent == confirmationComponent)
            {
                return(configurationComponents[configurationComponents.Count - 1]);
            }
            else if (currentComponent == progressComponent)
            {
                return(null);
            }
            else if (currentComponent == resultsComponent)
            {
                return(progressComponent);
            }
            else
            {
                for (int i = 1; i < configurationComponents.Count; i++)
                {
                    if (currentComponent == configurationComponents[i])
                    {
                        return(configurationComponents[i - 1]);
                    }
                }

                return(introductionComponent);
            }
        }
        public ProcedureDialog(String title, IProcedureComponent introductionComponent, List <IProcedureComponent> configurationComponents,
                               IProcedureComponent confirmationComponent, IProcedureProcessComponent progressComponent, IProcedureComponent resultsComponent)
        {
            InitializeComponent();
            this.Title = title;

            #region store procedure components
            if (introductionComponent == null || confirmationComponent == null ||
                progressComponent == null || resultsComponent == null ||
                configurationComponents == null || configurationComponents.Count == 0)
            {
                throw new Exception("NULL IProcedureComponent or empty configuration components list passed to initialization of ProcedureDialog");
            }

            this.introductionComponent = introductionComponent;
            this.confirmationComponent = confirmationComponent;
            this.progressComponent     = progressComponent;
            this.resultsComponent      = resultsComponent;

            this.configurationComponents = new List <IProcedureComponent>();
            for (int i = 0; i < configurationComponents.Count; i++)
            {
                this.configurationComponents.Add(configurationComponents[i]);
            }
            #endregion

            #region populate key
            introductionLabel.Content = introductionComponent.KeyText;
            confirmationLabel.Content = confirmationComponent.KeyText;
            progressLabel.Content     = progressComponent.KeyText;
            resultsLabel.Content      = resultsComponent.KeyText;

            StackPanel sP = new StackPanel();
            sP.Orientation = Orientation.Vertical;
            configurationExpander.Content = sP;

            for (int i = 0; i < configurationComponents.Count; i++)
            {
                Label configurationLabel = new Label();
                configurationLabel.Content  = configurationComponents[i].KeyText;
                configurationLabel.Margin   = new Thickness(30, 0, 0, 0);
                configurationLabel.Height   = 25;
                configurationLabel.Tag      = configurationComponents[i];
                configurationLabel.MouseUp += new MouseButtonEventHandler(configurationLabel_MouseUp);
                sP.Children.Add(configurationLabel);
            }
            #endregion

            #region load introduction
            contentGrid.Children.Add((UserControl)introductionComponent);
            currentComponent = introductionComponent;
            #endregion

            #region hook finish process
            progressComponent.ProcedureCompleteDelegates.Add(new ProcedureCompleteDelegate(finishProcess));
            #endregion

            updateKeyLinks();
        }
        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationChange((int)1, e);

            if (e.Handled)
            {
                currentComponent = getNext(currentComponent);
                contentGrid.Children.Clear();
                contentGrid.Children.Add((UserControl)currentComponent);

                updateButtons();
            }
        }
        private void resultsLabel_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (procedureComplete && currentComponent == progressComponent)
            {
                this.NavigationChange((int)-1, e);

                if (e.Handled)
                {
                    currentComponent = resultsComponent;
                    contentGrid.Children.Clear();
                    contentGrid.Children.Add((UserControl)currentComponent);

                    updateButtons();
                }
            }
        }
        private void confirmationLabel_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (currentComponent != confirmationExpander && currentComponent != progressComponent &&
                currentComponent != resultsComponent)
            {
                this.NavigationChange((int)-1, e);

                if (e.Handled)
                {
                    currentComponent = confirmationComponent;
                    contentGrid.Children.Clear();
                    contentGrid.Children.Add((UserControl)currentComponent);

                    updateButtons();
                }
            }
        }
        private void finishButton_Click(object sender, RoutedEventArgs e)
        {
            if (currentComponent == confirmationComponent)
            {
                #region confirm action
                if (ShowProcessWarning)
                {
                    if (MessageBox.Show(this, "Are you sure you wish to continue?\r\n\r\nPerforming this operation may not be reversable or cancellable, and may take considerable time.", this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }
                #endregion

                currentComponent = getNext(currentComponent);
                contentGrid.Children.Clear();
                contentGrid.Children.Add((UserControl)currentComponent);

                updateButtons();

                processing = true;

                progressComponent.startProcedure();
            }
            else if (currentComponent == progressComponent)
            {
                currentComponent = getNext(currentComponent);
                contentGrid.Children.Clear();
                contentGrid.Children.Add((UserControl)currentComponent);
                updateButtons();
            }
            else if (currentComponent == resultsComponent)
            {
                procedureComplete = true;
                if (this.AskedForClose != null)
                {
                    this.AskedForClose(this, new EventArgs());
                }
                else
                {
                    this.Close();
                }
            }
        }