Exemplo n.º 1
0
        public ButtonDisplayInfo Clone()
        {
            ButtonDisplayInfo bdi = new ButtonDisplayInfo
            {
                Label       = this.Label,
                Icon        = this.Icon,
                Description = this.Description,
            };

            return(bdi);
        }
        internal static ButtonDisplayInfo CreateButtonDisplayInfoForToolbarItem(AddToolbarItem item)
        {
            ButtonDisplayInfo bdi = new ButtonDisplayInfo();
            bdi.Description = item.Description;

            // If no icon location is available, default to a "screwdriver and wrench" image by default
            if (!String.IsNullOrEmpty(item.IconUrl))
            {
                bdi.Icon = item.IconUrl;
            }
            else
            {
                bdi.Icon = GetDefaultIconUrl(item.ToolbarItemType);
            }

            bdi.Label = item.Name;
            return bdi;
        }
        public ButtonDisplayInfo Clone()
        {
            ButtonDisplayInfo bdi = new ButtonDisplayInfo
            {
                Label = this.Label,
                Icon = this.Icon,
                Description = this.Description,
            };

            return bdi;
        }
        private void AddGroup_Click(object sender, RoutedEventArgs e)
        {
            // Make sure there is a selected item in the tree
            TreeViewItem selectedItem = ToolbarConfigurationTree.SelectedItem as TreeViewItem;
            if (selectedItem == null)
                return;

            // Make sure the selected item is a root node or an immediate child which is required to add a
            // group button.
            TreeViewItem itemParent = null;
            bool expandParent = false;
            int insertPosition = 0;

            GetParentAndPosition(selectedItem, out itemParent, out insertPosition, out expandParent);
            if (itemParent == null)
            {
                ESRIControls.MessageBoxDialog.Show(ESRI.ArcGIS.Mapping.Builder.Resources.Strings.RootLevelToAddGroup,
                    ESRI.ArcGIS.Mapping.Builder.Resources.Strings.CannotAddGroupButton, MessageBoxButton.OK);
                return;
            }

            ToolPanel tbar = ToolPanels[itemParent.Name];
            // Create display info to encapsulate the new group's display properties
            ButtonDisplayInfo displayInfo = new ButtonDisplayInfo()
            {
                Description = ESRI.ArcGIS.Mapping.Builder.Resources.Strings.DefaultGroupButtonDescription,
                Label = ESRI.ArcGIS.Mapping.Builder.Resources.Strings.DefaultGroupButtonLabel,
                Icon = ToolbarManagement.GetDefaultGroupIconUrl()
            };

            // Create command to configure the group
            ConfigureToolPanelItemCommand configureCommand = new ConfigureToolPanelItemCommand()
            {
                DisplayInfo = displayInfo,
                DialogTitle = ESRI.ArcGIS.Mapping.Builder.Resources.Strings.AddGroupButton
            };

            // Wire to the completed event to add the new group 
            configureCommand.Completed += (o, args) =>
            {
                // Create group button and add it to the proper toolbar
                DropDownButton galleryButton =
                    tbar.AddToolGroupButton(displayInfo, null, tbar.ToolPanelItems, insertPosition) as DropDownButton;

                // Create treeview item and add to the tree control
                TreeViewItem newNode = createTreeViewNodeForToolGroupButton(ToolType.ToolTypeGroup, displayInfo);
                newNode.IsSelected = true;

                // Add node to the designated parent
                if (insertPosition < 0)
                    itemParent.Items.Add(newNode);
                else
                    itemParent.Items.Insert(insertPosition, newNode);

                // Re-apply the header to cause UI update
                DataTemplate dt = newNode.HeaderTemplate;
                newNode.HeaderTemplate = null;
                newNode.HeaderTemplate = dt;
            };

            // Execute the configuration command
            configureCommand.Execute(null);
        }
        private TreeViewItem createTreeViewNodeForToolButton(ToolType toolType, ButtonDisplayInfo dataContext)
        {
            TreeViewItem node = new TreeViewItem()
            {
                Header = dataContext,
                Tag = toolType,
                HeaderTemplate = ToolbarControlNodeDataTemplate,
                ItemContainerStyle = LayoutRoot.Resources["TreeViewItemStyle"] as Style
            };
            // Use item description (if any) for the tooltip
            if (!String.IsNullOrEmpty(dataContext.Description))
            {
                System.Windows.Data.Binding b = new System.Windows.Data.Binding("Description") { Source = dataContext };
                node.SetBinding(ToolTipService.ToolTipProperty, b);
            }

            return node;
        }
        private ButtonBase createButton(ButtonDisplayInfo buttonDisplayInfo, ICommand buttonCommand, Style buttonStyle, bool isToggleButton)
        {
            ButtonBase btn = null;
            try
            {
                if (isToggleButton)
                {
                    btn = new ToggleButton();
                    btn.Click += OnToggleButtonClicked;
                    IToggleCommand toggleCommand = buttonCommand as IToggleCommand;
                    if (toggleCommand != null)
                    {
                        ToggleButton toggleButton = btn as ToggleButton;
                        if (toggleButton != null)
                            toggleButton.IsChecked = toggleCommand.IsChecked();
                    }
                }
                else
                    btn = new Button();

                btn.Style = buttonStyle;
                btn.DataContext = buttonDisplayInfo;
                btn.Command = buttonCommand;
                btn.CommandParameter = Context;

                if (buttonCommand != null)
                    buttonCommand.CanExecuteChanged += command_CanExecuteChanged;
                AllButtons.Add(btn);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return btn;
        }
        public void AddNestedToolButton(ButtonDisplayInfo buttonDisplayInfo, ICommand buttonCommand,
            ButtonBase parentButton, int position = -1)
        {
            DropDownButton parentDropDownButton = parentButton as DropDownButton;
            if (parentDropDownButton != null)
            {
                Panel panel = parentDropDownButton.PopupContent as Panel;
                if (panel != null)
                {
                    bool isToggleCommand = buttonCommand is IToggleCommand;
                    ButtonBase btn = createButton(buttonDisplayInfo, buttonCommand, isToggleCommand ? ToolPanelLayoutStyleHelper.Instance.GetStyle("MenuItemToggleButtonStyle") : ToolPanelLayoutStyleHelper.Instance.GetStyle("MenuItemStyle"), isToggleCommand);
                    btn.Click += nestedToolNode_Click;
                    btn.Tag = parentDropDownButton;

                    if (position < 0 || position >= panel.Children.Count)
                    {
                        panel.Children.Add(btn);
                        if (buttonCommand != null)
                            toolItems.Add(buttonCommand);
                    }
                    else
                    {
                        panel.Children.Insert(position, btn);
                        if (buttonCommand != null)
                            toolItems.Insert(position, buttonCommand);
                    }
                }
            }
        }
        public ButtonBase AddToolGroupButton(ButtonDisplayInfo buttonDisplayInfo, ICommand buttonCommand, IList<FrameworkElement> parentContainer, int position = -1)
        {
            string menuButtonStyle = isPopupToolPanel ? "PopupMenuButtonStyle" : "MenuButtonStyle";
            ButtonBase btn = createButton(buttonDisplayInfo, buttonCommand, ToolPanelLayoutStyleHelper.Instance.GetStyle(menuButtonStyle), false);
            btn.Click += groupNodeButton_Click;

            StackPanel stackPanel = new StackPanel();
            DropDownButton dropDownButton = new DropDownButton()
            {
                Content = btn,
                PopupContent = stackPanel,
                PopupContentContainerStyle = ToolPanelLayoutStyleHelper.Instance.GetStyle(PopupStyleName.PopupContentControl.ToString()),
                PopupLeaderStyle = ToolPanelLayoutStyleHelper.Instance.GetStyle(PopupStyleName.PopupLeader.ToString()),
            };
            if (position < 0 || position >= parentContainer.Count)
            {
                parentContainer.Add(dropDownButton);
                if (buttonCommand != null)
                    toolItems.Add(buttonCommand);
            }
            else
            {
                parentContainer.Insert(position, dropDownButton);
                if (buttonCommand != null)
                    toolItems.Insert(position, buttonCommand);
            }

            return dropDownButton;
        }
        public ButtonBase AddToolButton(ButtonDisplayInfo buttonDisplayInfo, ICommand buttonCommand,
            IList<FrameworkElement> parentContainer, int position = -1)
        {
            string toolToggleButtonStyle = isPopupToolPanel ? "PopupToolToggleButtonStyle" : "ToolToggleButtonStyle";
            string toolButtonStyle = isPopupToolPanel ? "PopupToolButtonStyle" : "ToolButtonStyle";

            bool isToggleCommand = buttonCommand is IToggleCommand;
            ButtonBase btn = createButton(buttonDisplayInfo, buttonCommand, isToggleCommand ? ToolPanelLayoutStyleHelper.Instance.GetStyle(toolToggleButtonStyle) : ToolPanelLayoutStyleHelper.Instance.GetStyle(toolButtonStyle), isToggleCommand);
            if (position < 0 || (parentContainer != null && position >= parentContainer.Count))
            {
                if(parentContainer != null)
                    parentContainer.Add(btn);
                if (buttonCommand != null)
                    toolItems.Add(buttonCommand);
            }
            else
            {
                if (parentContainer != null)
                    parentContainer.Insert(position, btn);
                if (buttonCommand != null)
                    toolItems.Insert(position, buttonCommand);
            }

            // Coded UI support.
            btn.Content = buttonDisplayInfo.Label;

            return btn;
        }
 private static void setButtonDisplayAttributesOnElement(ButtonDisplayInfo buttonDisplayInfo, XElement element)
 {
     if (element == null)
         return;
     if (!string.IsNullOrWhiteSpace(buttonDisplayInfo.Label))
         element.SetAttributeValue(Constants.LABEL, buttonDisplayInfo.Label);
     if (!string.IsNullOrWhiteSpace(buttonDisplayInfo.Icon))
         element.SetAttributeValue(Constants.ICON, buttonDisplayInfo.Icon);
     if (!string.IsNullOrWhiteSpace(buttonDisplayInfo.Description))
         element.SetAttributeValue(Constants.DESCRIPTION, buttonDisplayInfo.Description);
 }
 private static ButtonDisplayInfo getButtonDisplayInfoForXmlNode(XElement childNode)
 {
     string labelText = getAttributeValue(childNode, Constants.LABEL) ?? "";
     string icon = getAttributeValue(childNode, Constants.ICON) ?? "";
     string tooltipText = getAttributeValue(childNode, Constants.DESCRIPTION) ?? "";
     ButtonDisplayInfo displayInfo = new ButtonDisplayInfo() { Label = labelText, Icon = icon, Description = tooltipText };
     return displayInfo;
 }
 private TreeViewItem createTreeViewNodeForToolButton(ButtonDisplayInfo btnDisplayInfo)
 {
     TreeViewItem node = new TreeViewItem()
     {
         Header = btnDisplayInfo,
         HeaderTemplate = ToolbarControlNodeDataTemplate,
         ItemContainerStyle = LayoutRoot.Resources["TreeViewItemStyle"] as Style
     };
     return node;
 }