/// <summary>
 /// Updates attached properties that determine whether to show the configure button
 /// and what its behavior is on click
 /// </summary>
 private void updateConfigureButton(Wizard wizard)
 {
     ISupportsConfiguration configurableCommand = Class as ISupportsConfiguration;
     if (configurableCommand != null && Class as ISupportsWizardConfiguration == null)
     {
         ControlExtensions.SetExtendedUIVisibility(wizard, Visibility.Visible);
         ControlExtensions.SetExtendedCommand(wizard,
             new ParameterlessDelegateCommand(configurableCommand.Configure, delegate { return true; }));
     }
     else
     {
         ControlExtensions.SetExtendedUIVisibility(wizard, Visibility.Collapsed);
         ControlExtensions.SetExtendedCommand(wizard, null);
     }
 }
        /// <summary>
        /// Displays the configuration UI
        /// </summary>
        /// <param name="parameter">The object to be configured as a tool panel item</param>
        public void Execute(object parameter)
        {
            if (configurationUI == null)
            {
                // Get the command to configure
                WizardConfiguration = parameter as ISupportsWizardConfiguration ?? WizardConfiguration;
                if (WizardConfiguration != null)
                    configurationUI = createWizard();

            }

            if (configurationUI.CurrentPage == null && configurationUI.Pages != null &&
                configurationUI.Pages.Count > 0)
                configurationUI.CurrentPage = configurationUI.Pages[0];

            MapApplication.Current.ShowWindow(DialogTitle, configurationUI, IsModal, null, (e,o)=>
            {
                Wizard wiz = e as Wizard;
                if (wiz != null)
                    wiz.CurrentPage = null;

                if (_configurationComplete)
                {
                    // Hide configuration UI and fire the completed event
                    if (WizardConfiguration != null)
                        WizardConfiguration.OnCompleted();

                    if (Completed != null)
                        Completed(this, EventArgs.Empty);
                }
                else
                {
                    if (WizardConfiguration != null)
                        WizardConfiguration.OnCancelled();

                    if (Cancelled != null)
                        Cancelled(this, EventArgs.Empty);
                }
                _configurationComplete = false;
            }, WindowType.DesignTimeFloating);
        }
        private Wizard createWizard()
        {
            Wizard wizard = new Wizard();

            // Include page to select tool
            if (AllowToolSelection)
            {
                AvailableToolbarItemsControl toolList = new AvailableToolbarItemsControl(false)
                    {
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        HorizontalContentAlignment = HorizontalAlignment.Stretch,
                        Margin = new Thickness(0,5,0,0)
                    };
                WizardPage toolSelectionPage = new WizardPage()
                {
                    Content = toolList,
                    Heading = ESRI.ArcGIS.Mapping.Builder.Resources.Strings.SelectAToolToAdd
                };
                wizard.Pages.Add(toolSelectionPage);
                _locallyInsertedWizardPagesCount++;

                toolList.SelectedItemChanged += (o, e) =>
                {
                    toolSelectionPage.InputValid = toolList.SelectedToolItemType != null;

                    // If a new command is selected, rebuild the wizard pages
                    if (toolSelectionPage.InputValid && toolList.SelectedClass != null && !toolList.SelectedClass.Equals(Class))
                    {
                        // Remove pages collection changed handler from previously selected tool
                        ISupportsWizardConfiguration previousWizardConfigInterface = 
                            Class as ISupportsWizardConfiguration;
                        if (previousWizardConfigInterface != null)
                            previousWizardConfigInterface.Pages.CollectionChanged -= WizardInterfacePages_CollectionChanged;

                        Class = toolList.SelectedClass;
                        DisplayInfo = toolList.SelectedItemDisplayInfo;

                        // All but the page showing the available tools will be removed, so reset the number of
                        // pages added to the wizard by the command to one.
                        _locallyInsertedWizardPagesCount = 1;

                        List<WizardPage> configPages = createWizardPages();
                        int pagesToRemove = wizard.Pages.Count - 1;

                        // Add the new config pages to the wizard, then remove the old ones
                        foreach (WizardPage page in configPages)
                            wizard.Pages.Add(page);

                        for (int i = 0; i < pagesToRemove; i++)
                            wizard.Pages.RemoveAt(1);

                        updateConfigureButton(wizard);

                        // Initialize CurrentPage if command implements ISupportsWizardConfiguration
                        ISupportsWizardConfiguration wizardConfigInterface = Class as ISupportsWizardConfiguration;
                        if (wizardConfigInterface != null)
                        {
                            wizardConfigInterface.Pages.CollectionChanged += WizardInterfacePages_CollectionChanged;
                            wizardConfigInterface.CurrentPage = toolSelectionPage;
                        }
                    }
                };

                Size maxPageSize = getMaxPageSize(toolList.AvailableItems);
                if (maxPageSize.Height > 0 && maxPageSize.Width > double.MinValue)
                {
                    wizard.ContentHeight = maxPageSize.Height;
                    wizard.ContentWidth = maxPageSize.Width > 400 ? maxPageSize.Width : 400;
                }
            }
            else
            {
                // Get wizard config interface and use to initialize wizard size
                ISupportsWizardConfiguration wizardConfigInterface = Class as ISupportsWizardConfiguration;
                if (wizardConfigInterface != null)
                {
                    wizard.ContentHeight = wizardConfigInterface.DesiredSize.Height;
                    wizard.ContentWidth = wizardConfigInterface.DesiredSize.Width;
                    wizardConfigInterface.Pages.CollectionChanged += WizardInterfacePages_CollectionChanged;
                }
            }

            // initialize wizard pages
            List<WizardPage> pages = createWizardPages();
            foreach (WizardPage page in pages)
                wizard.Pages.Add(page);

            updateConfigureButton(wizard);

            // Wire events
            wizard.PageChanging += Wizard_PageChanging;
            wizard.PageChanged += Wizard_PageChanged;
            wizard.Cancelled += Wizard_Cancelled;
            wizard.Completed += Wizard_Completed;

            return wizard;
        }
        private Wizard createWizard()
        {
            Wizard wizard = new Wizard();
            if (_wizardStyle != null)
                wizard.Style = WizardStyle;
            // Get wizard config interface and use to initialize wizard size
            wizard.ContentHeight = WizardConfiguration.DesiredSize.Height;
            wizard.ContentWidth = WizardConfiguration.DesiredSize.Width;

            // initialize wizard pages
            IEnumerable<WizardPage> pages = WizardConfiguration.Pages;
            foreach (WizardPage page in pages)
                wizard.Pages.Add(page);

            // Wire events
            wizard.PageChanging += Wizard_PageChanging;
            wizard.PageChanged += Wizard_PageChanged;
            wizard.Cancelled += Configuration_Cancelled;
            wizard.Completed += Configuration_Completed;

            return wizard;
        }