/// <summary> Event handler for having loaded the main window. </summary>
        /// <param name="sender"> The sender of the Loaded event. </param>
        /// <param name="e"> The event parameters. </param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            bool result = ConfigureWPFMap(wpfMap);

            if (!result)
            {
                var authenticationOK = UseCase.ManagedAuthentication.Set("api-eu-test", DefaultXServerInternetToken.Value);

                if (authenticationOK)
                {
                    ConfigureWPFMap(wpfMap);
                }
                else
                {
                    var msgBox = new MsgBox("Connection failed", UseCase.ManagedAuthentication.ErrorMessage);
                    msgBox.ShowDialog();
                }
            }

            // use case 'XServerConnection'
            XURLComboBox.DefaultText("Enter URL here", Properties.Settings.Default.XUrl);

            bool useDefaultToken = DefaultXServerInternetToken.Value.Equals(Properties.Settings.Default.XToken) ||
                                   string.IsNullOrEmpty(Properties.Settings.Default.XToken);

            XTokenToggleButton.IsChecked = XTokenTextBox.IsReadOnly = useDefaultToken;
            XTokenTextBox.DefaultText("Azure: Enter xToken here", useDefaultToken
                ? DefaultXServerInternetToken.Value + " (Trial-Key)"
                : Properties.Settings.Default.XToken);

            // Use case 'HERE'
            HereAppIdTextBox.DefaultText("Enter AppId here", Properties.Settings.Default.HereAppId);
            HereAppCodeTextBox.DefaultText("Enter AppCode here", Properties.Settings.Default.HereAppCode);

            // Use case 'Clustering'
            clusteringUseCase.CheckBoxToDisable = ClusteringCheckBox;

            // Use case 'Additional WPF map'
            // For a dynamic extension of the column's count, a default column definition has to be inserted.
            MapGrid.ColumnDefinitions.Add(new ColumnDefinition {
                MinWidth = 50
            });

            // Use case 'Switch UI theme'
            UIThemeComboBox.SelectedIndex = 2; // This item corresponds to default theme

            // Use case 'Switch map style'
            ProfileComboBox.Text = "Silkysand";
            ProfileOKButton_OnClick(null, null);

            // Use case 'xLocate'
            DeactivatedGeocodingRadiobutton.IsChecked = true;
            SingleFieldInput.Visibility = Visibility.Collapsed;
            MultiFieldInput.Visibility  = Visibility.Collapsed;

            // Use case 'Tour planning'
            TourScenarioComboBox.SelectedIndex = 0; // First item corresponds to 'deactivated'
            TourPlanningStart.IsEnabled        = false;

            #region doc:TourPlanningAsynchronousEvents
            tourPlanningUseCase.Initialized = () =>
            {
                TourPlanningStart.IsEnabled = true;
            };

            tourPlanningUseCase.Progress = (progressMessage, percent) =>
            {
                TourPlanningStatus.Content    = progressMessage;
                TourPlanningProgressBar.Value = percent;
            };

            tourPlanningUseCase.Finished = () =>
            {
                TourPlanningStart.Content      = "Start planning";
                TourScenarioComboBox.IsEnabled = true;
                TourPlanningStart.IsEnabled    = true;
            };
            #endregion //doc:TourPlanningAsynchronousEvents

            #region Intro initializing
            if (Properties.Settings.Default.IntroSkipped)
            {
                return;
            }

            var demoCenterIntro = new DemoCenterInstructions(IntroGrid);
            demoCenterIntro.StartIntro();
            demoCenterIntro.HandlerCallback = (id, start) =>
            {
                switch (id)
                {
                case "Connection": if (start)
                    {
                        Menu.IsExpanded = xServerExpander.IsExpanded = true;
                    }
                    ConnectionIntroEllpise.Visibility = (start) ? Visibility.Visible : Visibility.Hidden;
                    break;

                case "xServerinternet": break;

                case "_SkippedIntro": Properties.Settings.Default.IntroSkipped = start;
                    Properties.Settings.Default.Save(); break;

                case "ExploreUsecases": if (start)
                    {
                        Menu.IsExpanded = RoutingExpander.IsExpanded = true;
                    }
                    PossibilitiesIntroEllpise.Visibility = (start) ? Visibility.Visible : Visibility.Hidden; break;
                }
            };

            #endregion
        }
        ///////////////////////////////////////////////////////////////////////
        #region Global handling of check boxes enabling the different use cases

        /// <summary> Event handler for changing the state of all check boxes, which enable/disable the individual use cases. </summary>
        /// <param name="sender"> The sender of the CheckedChanged event. </param>
        /// <param name="e"> The event parameters. </param>
        private void CheckBox_CheckedChanged(object sender, RoutedEventArgs e)
        {
            var state = ((CheckBox)sender).IsChecked ?? false;

            oldCursor = Cursor;
            Cursor    = Cursors.Wait;

            if (sender.Equals(HereCheckBox))
            {
                HereOkButton.IsEnabled = HereAppIdTextBox.IsEnabled = HereAppCodeTextBox.IsEnabled = state;
                if (state)
                {
                    EnableHereUseCase();
                }
                else
                {
                    hereUseCase.Activate(false, wpfMap);
                }
            }
            else if (sender.Equals(ClusteringCheckBox))
            {
                clusteringUseCase.Activate(state, wpfMap);
            }
            else if (sender.Equals(DifferentShapesCheckBox))
            {
                differentShapesUseCase.Activate(ShapesUseLabelsCheckBox.IsEnabled = state, wpfMap);
            }
            else if (sender.Equals(AddWpfMapCheckBox))
            {
                if (state)
                {
                    InsertWpfMap();
                }
                else
                {
                    RemoveWpfMap();
                }
            }
            else if (sender.Equals(GeoRSSCheckBox))
            {
                geoRssUseCase.Activate(state, wpfMap);
            }
            else if (sender.Equals(MapMarketCheckBox))
            {
                mapMarketController.Activate(state, wpfMap);
            }
            else if (sender.Equals(ShapeFileCheckBox))
            {
                shapeFileUseCase.Activate(state, wpfMap);
            }
            else if (sender.Equals(ManySymbolsCheckBox))
            {
                selectionUseCase.Activate(state, wpfMap);
            }
            else if (sender.Equals(WmsEnableCheckBox))
            {
                wmsUseCase.Activate(state, wpfMap);
                WmsUseTiledLayerCheckBox.IsEnabled = state;
            }
            else if (sender.Equals(WmsUseTiledLayerCheckBox))
            {
                wmsUseCase.UseTiledVersionOfGeobaseData = state;
            }
            // Feature Layer rendering check boxes
            else if (sender.Equals(TrafficIncidentsCheckBox))
            {
                featureLayerUseCase.UseTrafficIncidents = state;
                FeatureLayerCheckBox_Changed(sender, state);
            }
            else if (sender.Equals(TruckAttributesCheckBox))
            {
                featureLayerUseCase.UseTruckAttributes = state;
                FeatureLayerCheckBox_Changed(sender, state);
            }
            else if (sender.Equals(RestrictionZonesCheckBox))
            {
                featureLayerUseCase.UseRestrictionZones = state;
                FeatureLayerCheckBox_Changed(sender, state);
            }
            else if (sender.Equals(PreferredRoutesCheckBox))
            {
                featureLayerUseCase.UsePreferredRoutes = state;
                FeatureLayerCheckBox_Changed(sender, state);
            }
            else if (sender.Equals(SpeedPatternsCheckBox))
            {
                featureLayerUseCase.UseSpeedPatterns = state;
                FeatureLayerCheckBox_Changed(sender, state);
            }
            else if (sender.Equals(ElementaryRoutingCheckBox))
            {
                if (state)
                {
                    routingUseCase = new RoutingUseCase(wpfMap);        // Adding the xRoute elements.
                }
                else
                {
                    routingUseCase.Remove();
                }
            }
            else if (sender.Equals(XRouteDragAndDropCheckBox))
            {
                routingDragAndDropUseCase.Activate(state, wpfMap);

                if (dragDropInstruction == null)
                {
                    dragDropInstruction = new DemoCenterInstructions(IntroGrid);
                }

                if (state && !Properties.Settings.Default.DragDropIntroSkipped)
                {
                    dragDropInstruction.StartDragDropIntro();
                }
                dragDropInstruction.HandlerCallback = (id, start) =>
                {
                    switch (id)
                    {
                    case "_SkippedIntro":
                        Properties.Settings.Default.DragDropIntroSkipped = start;
                        Properties.Settings.Default.Save();
                        dragDropInstruction.isActive = false;
                        break;
                    }
                };
            }

            Cursor = oldCursor;
        }