コード例 #1
0
        private void OnContextMenuPreviewClick(object sender, MouseButtonEventArgs e)
        {
            var menu = Menu as ContextMenu;

            if (menu != null)
            {
                ContextMenuAdvancement.Add(this, menu);
            }
        }
コード例 #2
0
        private void OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            double relx;
            var    child = InternalChildren.OfType <FrameworkElement>().ElementAtOrDefault(GetChildId(e, out relx));
            var    menu  = child?.ContextMenu;

            if (menu != null)
            {
                if (relx < _labelWidth)
                {
                    menu.IsOpen = true;
                    e.Handled   = true;
                }
                else if (ContextMenuAdvancement.GetPropagateToChildren(child))
                {
                    ContextMenuAdvancement.PropagateToChildren(child);
                }
            }
        }
コード例 #3
0
        protected override void OnOpened(RoutedEventArgs e)
        {
            InheritingContextMenu previous = null;

            if (_previouslyOpened?.TryGetTarget(out previous) == true)
            {
                previous.RemoveTemporary();
            }

            RemoveTemporary();
            ContextMenuAdvancement.CheckTime();

            _menus = ContextMenuAdvancement.ParentContextMenu;
            if (_menus.Count == 0)
            {
                return;
            }

            _menus = _menus.Where(x => !ReferenceEquals(x.Item1, this)).ToList();
            ContextMenuAdvancement.ParentContextMenu.Clear();

            _items = new List <List <FrameworkElement> >(_menus.Count);
            foreach (var menu in _menus)
            {
                var sub = menu.Item1.Items.OfType <FrameworkElement>().ToList();
                foreach (var s in sub.OfType <MenuItem>())
                {
                    s.DataContext = menu.Item2;
                }

                _items.Add(sub);
                menu.Item1.Items.Clear();
            }

            if (OptionInsertInFront)
            {
                var i = 0;
                foreach (var group in _items)
                {
                    var any = false;
                    foreach (var item in group)
                    {
                        Items.Insert(i++, item);
                        item.Tag = TemporaryMark;
                        any      = true;
                    }

                    if (any)
                    {
                        Items.Insert(i++, new Separator {
                            Tag = TemporaryMark
                        });
                    }
                }
            }
            else
            {
                foreach (var group in _items)
                {
                    var any = false;
                    foreach (var item in group)
                    {
                        if (!any)
                        {
                            Items.Add(new Separator {
                                Tag = TemporaryMark
                            });
                        }

                        Items.Add(item);
                        item.Tag = TemporaryMark;
                        any      = true;
                    }
                }
            }

            _previouslyOpened = new WeakReference <InheritingContextMenu>(this);
            base.OnOpened(e);
        }