예제 #1
0
        public ContextMenuButton(IContextMenuTool tool, IContextType contextType, IMapDocument mapDocument)
        {
            this.Tool    = tool;
            _contextType = contextType;
            _doc         = mapDocument;

            base.Header = LocalizedResources.GetResString(tool.Name, tool.Name);
            base.Icon   = base.LargeIcon = ImageFactory.FromBitmap(tool.Image as global::System.Drawing.Image);

            base.Click += new RoutedEventHandler(ContextMenuButton_Click);
        }
예제 #2
0
        public ContextMenuButton(IContextMenuTool tool, IContextType contextType, IMapDocument mapDocument)
        {
            this.Tool    = tool;
            _contextType = contextType;
            _doc         = mapDocument;

            base.Header = LocalizedResources.GetResString(tool.Name, tool.Name);
            base.Icon   = base.LargeIcon = ImageFactory.FromBitmap(tool.Image as System.Drawing.Image);

            base.Click += new RoutedEventHandler(ContextMenuButton_Click);

            bool visible = false, enable = false;

            if (_contextType.ContextObject is IMap)
            {
                enable  = tool.Enable(contextType.ContextObject);
                visible = tool.Visible(contextType.ContextObject);
            }
            else if (_contextType.ContextObject is ITOCElement && ((ITOCElement)_contextType.ContextObject).Layers != null)
            {
                ITOCElement tocElement = (ITOCElement)_contextType.ContextObject;

                foreach (var layer in tocElement.Layers)
                {
                    if (visible == true && enable == true)
                    {
                        break;
                    }

                    if (!enable)
                    {
                        enable = tool.Enable(layer);
                    }
                    if (!visible)
                    {
                        visible = tool.Visible(layer);
                    }
                }
            }

            base.IsEnabled  = enable;
            base.Visibility = visible == false ? Visibility.Collapsed : Visibility.Visible;
        }