示例#1
0
        private Rectangle CreateHorizontalSeparator(string tag, double height, double?leftMarginMinWidth)
        {
            CloseOnClick = false;

            if (leftMarginMinWidth.HasValue)
            {
                ImageLeftMinWidth = leftMarginMinWidth.Value;
            }

            Color endColor = SeparatorEndColor;

            if (endColor.A + 10 <= 255)
            {
                endColor.A += 10;
            }

            HorizontalSeparator = new Rectangle
            {
                Height = height,
                Margin = new Thickness(-3, 0, -3, 0),
                Fill   = PopupMenuUtils.MakeColorGradient(SeparatorStartColor, endColor, 90)
            };

            DockPanel.SetDock(HorizontalSeparator, Dock.Top);

            if (tag != null)
            {
                HorizontalSeparator.Tag = tag;
            }

            this.Header = HorizontalSeparator;
            DockPanel.SetDock(HorizontalSeparator, Dock.Top);
            return(HorizontalSeparator);
        }
示例#2
0
        public PopupMenuItem(string iconUrl, object header, bool useDefaultTemplate, params UIElement[] items)
        {
            this.DefaultStyleKey = typeof(PopupMenuItem);

            VerticalSeparatorFill = PopupMenuUtils.MakeColorGradient(SeparatorStartColor, SeparatorEndColor, 0);

            ShowLeftMargin = useDefaultTemplate;
            ImagePath      = iconUrl;

            if (UseFirstItemAsHeader)
            {
                if (this.Items.Count > 0)
                {
                    FrameworkElement element = this.Items.First() as FrameworkElement;
                    this.Items.Remove(element);
                    // Use first child as header if the latter is not assigned
                    this.Header = element;
                    this.UpdateLayout();
                }
            }
            else
            {
                this.Header = header;
            }

            // Add custom elements if any
            if (items != null)
            {
                foreach (UIElement element in items.Where(el => el != null))
                {
                    if ((element as FrameworkElement).Parent is Panel)
                    {
                        ((element as FrameworkElement).Parent as Panel).Children.Remove(element);
                    }
                    this.Items.Add(element);
                }
            }

            this.Loaded += PopupMenuItem_Loaded;
        }