public GeoprocessingCommand()
        {
            if (MapApplication.Current.IsEditMode)
            {
                metadataLoader.LoadFailed += GPTaskEndpoint_LoadFailed;
                metadataLoader.LoadSucceeded += GPTaskEndpoint_LoadSucceeded;

                // initialize wizard pages
                initializeBrowsePage();
                inputParamsPage = new WizardPage()
                {
                    Heading = ESRI.ArcGIS.Mapping.GP.Resources.Strings.ConfigureInputHeading,
                    InputValid = true
                };
                outputParamsPage = new WizardPage()
                {
                    Heading = ESRI.ArcGIS.Mapping.GP.Resources.Strings.ConfigureOutputHeading,
                    InputValid = true
                };
                titleAndLayerOrderPage = new WizardPage()
                {
                    Heading = ESRI.ArcGIS.Mapping.GP.Resources.Strings.ConfigureTitleAndLayerOrder,
                    InputValid = true
                };
                errorPage = new WizardPage()
                {
                    Heading = new TextBlock()
                    {
                        Text = ESRI.ArcGIS.Mapping.GP.Resources.Strings.FailedToLoadTaskInformation,
                        FontWeight = FontWeights.Bold,
                    },
                    InputValid = false
                };
            }
        }
        // Creates the configuration pages for the search tool
        private ObservableCollection<WizardPage> createConfigPages()
        {
            ObservableCollection<WizardPage> configPages = new ObservableCollection<WizardPage>();

            // Create the page for specifying which searches to include
            ProviderSelectionView providerView = new ProviderSelectionView()
            {
                Margin = new Thickness(10),
            };

            m_searchSelectionPage = new WizardPage()
            {
                Heading = Strings.SelectSearchTypes,
                Content = providerView
            };

            // Initialize configuration ViewModel if necessary
            if (m_configViewModel == null)
                initConfigViewModel();

            // Set page's data context to the ViewModel
            providerView.DataContext = m_configViewModel;

            m_searchSelectionPage.InputValid = m_configViewModel.SelectedSearchProviders.Count > 0;

            // Add the page
            configPages.Add(m_searchSelectionPage);

            // Incorporate wizard info from current search providers
            addNewWizardInfo(m_configViewModel.SelectedSearchProviders, configPages);

            return configPages;
        }
        private void initializeBrowsePage()
        {
            // Create browse control
            browseDialog = new BrowseContentDialog()
            {
                Filter = Core.DataSources.Filter.GeoprocessingServices,
                DataSourceProvider = ViewUtility.GetDataSourceProvider(),
                ConnectionsProvider = ViewUtility.GetConnectionsProvider(),
                Style = ResourceUtility.LoadEmbeddedStyle("Themes/GPBrowseStyle.xaml", "GPBrowseStyle"),
                SelectedResourceUrl = configuration != null && configuration.TaskEndPoint != null ?
                    configuration.TaskEndPoint.AbsoluteUri : null,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                HorizontalContentAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                VerticalContentAlignment = VerticalAlignment.Stretch
            };

            if (configuration != null)
                browseDialog.ShowRestrictedServices = configuration.UseProxy;

            // Encapsulate browse control in a wizard page
            browsePage = new WizardPage()
            {
                Content = browseDialog,
                Heading = ESRI.ArcGIS.Mapping.GP.Resources.Strings.BrowseToGP,                
            };

            // Bind the selected resource URL of the browse control to whether the input 
            // of the browse page is valid.  Validation state will be updated when the 
            // selected resource is updated.
            Binding b = new Binding("SelectedResourceUrl")
            {
                Source = browseDialog,
                Converter = new IsNotNullOrEmptyConverter()
            };
            BindingOperations.SetBinding(browsePage, WizardPage.InputValidProperty, b);

            // When a new GP task is selected, wire handler to retrieve info from service endoint
            browseDialog.SelectedResourceChanged += GPTaskEndpoint_Changed;
        }
        // Generates wizard pages for configuring the search provider
        private ObservableCollection<WizardPage> createConfigPages()
        {
            ObservableCollection<WizardPage> configPages = new ObservableCollection<WizardPage>();

            // Create page for selecting locator service
            LocatorConfigView configView = new LocatorConfigView()
            {
                Margin = new Thickness(10, 13, 10, 0),
                DataContext = this
            };

            _locatorConfigPage = new WizardPage()
            {
                Content = configView,
                InputValid = LocatorInfo != null
            };

            // Setup binding for page heading
            bindDisplayNameToHeading(_locatorConfigPage, "ConfigureLocatorService");

            // Create page for specifying how to zoom to results
            ResultZoomExtentConfigView zoomExtentConfigView = new ResultZoomExtentConfigView() 
            { 
                Margin = new Thickness(10, 17, 10, 5),
                DataContext = this
            };

            _zoomExtentConfigPage = new WizardPage()
            {
                Content = zoomExtentConfigView
            };
            validateZoomExtentConfigPage();

            // Setup binding for page heading
            bindDisplayNameToHeading(_zoomExtentConfigPage, "ConfigureResultExtent");


            // Add pages
            configPages.Add(_locatorConfigPage);
            configPages.Add(_zoomExtentConfigPage);

            return configPages;
        }
        /// <summary>
        /// Binds the providers display name into the heading of the wizard page, using
        /// a resource string to determine the text surrounding the display name
        /// </summary>
        private void bindDisplayNameToHeading(WizardPage page, string resourceName)
        {
            // Binding XAML that will plug the display name (local:Properties.DisplayName) into
            // a string resource that has a format parameter 
            string xaml = string.Format(
                @"<Binding xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
                            xmlns:local=""clr-namespace:SearchTool;assembly=SearchTool.AddIns""        
                            Path=""(local:Properties.DisplayName)"" ConverterParameter=""{0}"">
                                <Binding.Converter>
                                    <local:FormatResourceConverter />
                                </Binding.Converter>
                            </Binding>", resourceName);

            Binding b = XamlReader.Load(xaml) as Binding;
            b.Source = this;

            // Plug the binding into the wizard page's heading
            BindingOperations.SetBinding(page, WizardPage.HeadingProperty, b);
        }
        /// <summary>
        /// Creates configuration wizard pages for the current command
        /// </summary>
        /// <returns>The list of wizard pages</returns>
        private List<WizardPage> createWizardPages()
        {
            List<WizardPage> pages = new List<WizardPage>();

            EditToolbarItemControl toolPropsUI = createToolPropertiesUI();
            toolPropsUI.Margin = new Thickness(5, 8, 5, 0);
            // Encapsulate properties dialog in a wizard page
            WizardPage toolPropsPage = new WizardPage()
            {
                Content = toolPropsUI,
                Heading = ESRI.ArcGIS.Mapping.Builder.Resources.Strings.SpecifyToolProperties,
                InputValid = toolPropsUI.InputValid
            };

            // Update wizard page validation state on tool properties validation state change
            toolPropsUI.ValidationStateChanged += (o, e) => { toolPropsPage.InputValid = toolPropsUI.InputValid; };

            // initialize wizard pages
            pages.Add(toolPropsPage);
            _locallyInsertedWizardPagesCount++;


            // Get pages from wizard config interface and add to collection
            ISupportsWizardConfiguration wizardConfig = Class as ISupportsWizardConfiguration;
            if (wizardConfig != null)
            {
                foreach (WizardPage page in wizardConfig.Pages)
                    pages.Add(page);
            }

            return pages;
        }
        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 int getPageIndex(WizardPage page)
        {
            int index = -1;
            if (page != null)
            {
                for (int i = 0; i < Pages.Count; i++)
                {
                    if (page.Equals(Pages[i]))
                    {
                        index = i;
                        break;
                    }
                }
            }

            return index;
        }
 public bool PageChanging()
 {
     // Store reference to current wizard page before page changes
     lastPage = CurrentPage;
     return true;
 }
        public ObservableCollection<WizardPage> GetWizardPages()
        {
            if (selectEditableLayers == null)
            {
                SelectLayers selectLayers = new SelectLayers();
                selectLayers.DataContext = Configuration;
                selectEditableLayers = new WizardPage()
                {
                    Content = selectLayers,
                    Heading = ESRI.ArcGIS.Mapping.Controls.Editor.Resources.Strings.SelectLayersHeader,
                    InputValid = true
                };
            }

            if (editorOptions == null)
            {
                EditorOptions options = new EditorOptions();
                options.DataContext = Configuration;
                editorOptions = new WizardPage()
                {
                    Content = options,
                    Heading = ESRI.ArcGIS.Mapping.Controls.Editor.Resources.Strings.EditorOptionsHeader,
                    InputValid = true
                };
            }

            // Add pages to wizard
            ObservableCollection<WizardPage> pages = new ObservableCollection<WizardPage>();
            pages.Add(selectEditableLayers);
            pages.Add(editorOptions);
            return pages;
        }