private void ToolMenuButton_SelectedButtonChange(object sender, MenuButtonChangeEventArgs e)
 {
     if (e.NewButton != null)
     {
         toolMode = (MapActionMode)Enum.Parse(typeof(MapActionMode), (string)e.NewButton.Tag, true);
         this.ResetDrawObjectMode();
     }
 }
        protected override void InitializeControls()
        {
            if (AppConfig == null)
            {
                return;
            }
            if (AppConfig.TaskbarConfig == null)
            {
                return;
            }

            LogoImage.Style    = (this.CurrentApp.Resources.Contains("LogoImageStyle")) ? (this.CurrentApp.Resources["LogoImageStyle"] as Style) : null;
            StackToolbar.Style = (this.CurrentApp.Resources.Contains("AppToolbarStyle")) ? (this.CurrentApp.Resources["AppToolbarStyle"] as Style) : (this.CurrentApp.Resources["defaultAppToolbarStyle"] as Style);

            // Initialize Tool Buttons
            if (AppConfig.TaskbarConfig.MapToolButtons.Length > 0)
            {
                ToolMenuButton = new SwitchMenuButton()
                {
                    IsTabStop = true, MenuOpenMode = MenuOpenAction.MouseHover
                };                                                                                                      // Do not set Width and Height
                ToolMenuButton.Style             = (this.CurrentApp.Resources.Contains("SwitchMenuButtonStyle")) ? (this.CurrentApp.Resources["SwitchMenuButtonStyle"] as Style) : (this.CurrentApp.Resources["defaultSwitchMenuButtonStyle"] as Style);
                ToolMenuButton.MenuButtonChange += new MenuButtonChangeEventHandler(ToolMenuButton_SelectedButtonChange);
                StackToolbar.Children.Add(ToolMenuButton);

                foreach (MapToolButton btnTool in AppConfig.TaskbarConfig.MapToolButtons)
                {
                    if (btnTool.IsDefault)
                    {
                        this.toolMode = (MapActionMode)Enum.Parse(typeof(MapActionMode), btnTool.MapAction, true);
                    }
                    CircleMenuButton toolButton = new CircleMenuButton()
                    {
                        Width = 50, Height = 50, Text = btnTool.Title, Tag = btnTool.MapAction
                    };
                    toolButton.ImageSource = new BitmapImage(new Uri(btnTool.ButtonImage, UriKind.Relative));
                    toolButton.IsSelected  = btnTool.IsDefault;
                    ToolMenuButton.Items.Add(toolButton);
                }
            }

            // Initialize Base Map Toggle Button
            if (AppConfig.MapConfig.BaseMap != null)
            {
                LayerConfig[] lyrConfigs = null;
                BaseMapConfig baseConfig = AppConfig.MapConfig.BaseMap;

                if (baseConfig.EnableBase == ServiceSource.BING && baseConfig.BingBaseMap != null)
                {
                    lyrConfigs = baseConfig.BingBaseMap.Layers;
                }
                else if (baseConfig.ArcGISBaseMap != null)
                {
                    lyrConfigs = baseConfig.ArcGISBaseMap.Layers;
                }

                if ((lyrConfigs != null) && (lyrConfigs.Length > 1))
                {
                    BaseMenuButton = new SwitchMenuButton()
                    {
                        IsTabStop = true, MenuOpenMode = MenuOpenAction.MouseHover
                    };                                                                                                      // Do not set Width and Height
                    BaseMenuButton.Style             = (this.CurrentApp.Resources.Contains("SwitchMenuButtonStyle")) ? (this.CurrentApp.Resources["SwitchMenuButtonStyle"] as Style) : (this.CurrentApp.Resources["defaultSwitchMenuButtonStyle"] as Style);
                    BaseMenuButton.MenuButtonChange += new MenuButtonChangeEventHandler(BaseMenuButton_SelectedButtonChange);
                    StackToolbar.Children.Add(BaseMenuButton);

                    foreach (LayerConfig config in lyrConfigs)
                    {
                        SquareMenuButton baseButton = new SquareMenuButton()
                        {
                            Width = 50, Height = 50, Text = config.Title, Tag = config
                        };
                        baseButton.ImageSource = new BitmapImage()
                        {
                            UriSource = new Uri(config.IconSource, UriKind.Relative)
                        };
                        baseButton.IsSelected = config.VisibleInitial;
                        BaseMenuButton.Items.Add(baseButton);
                    }
                }
            }

            // Initialize Help Menu Button
            if (AppConfig.AppHelpMenu != null)
            {
                LinkMenuButton = new DropMenuButton()
                {
                    Text = "Help", Width = 50, Height = 50, VerticalContentAlignment = System.Windows.VerticalAlignment.Bottom, HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left
                };
                LinkMenuButton.Style          = (this.CurrentApp.Resources.Contains("DropMenuButtonStyle")) ? (this.CurrentApp.Resources["DropMenuButtonStyle"] as Style) : (this.CurrentApp.Resources["defaultDropMenuButtonStyle"] as Style);
                LinkMenuButton.ImageSource    = new BitmapImage(new Uri(AppConfig.AppHelpMenu.MenuIcon, UriKind.Relative));
                LinkMenuButton.MenuItemClick += new MenuItemClickEventHandler(LinkMenuButton_MenuItemClick);
                StackToolbar.Children.Add(LinkMenuButton);

                foreach (ApplicationLink link in AppConfig.AppHelpMenu.Links)
                {
                    ImageSource     iconSource = new BitmapImage(new Uri(link.Icon, UriKind.Relative));
                    ContextMenuItem menuItem   = new ContextMenuItem()
                    {
                        Text = link.Title, IconSource = iconSource, Tag = link.Url, UseSmallIcon = true, Margin = new Thickness(1)
                    };
                    menuItem.Background = new SolidColorBrush(Colors.Transparent);
                    LinkMenuButton.MenuItems.Add(menuItem);
                }

                if (AppConfig.AppHelpMenu.About != null)
                {
                    ImageSource     iconSource = new BitmapImage(new Uri(AppConfig.AppHelpMenu.About.Icon, UriKind.Relative));
                    ContextMenuItem menuItem   = new ContextMenuItem()
                    {
                        Text = AppConfig.AppHelpMenu.About.Title, IconSource = iconSource, Tag = "About", UseSmallIcon = true, Margin = new Thickness(1)
                    };
                    menuItem.Background = new SolidColorBrush(Colors.Transparent);
                    LinkMenuButton.MenuItems.Add(menuItem);
                }
            }
        }