示例#1
0
        static TreeViewItem GetItemAndScrollIntoView(TreeView tree, ItemsControl parent, int i)
        {
            var peer           = ItemsControlAutomationPeer.CreatePeerForElement(tree);
            var scrollProvider = peer.GetPattern(PatternInterface.Scroll) as IScrollProvider;
            var direction      = ScrollAmount.SmallIncrement;

            while (true)
            {
                var item = parent.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
                if (item != null)
                {
                    item.BringIntoView();
                    InvokeUtility.DoEvents();
                    return(item);
                }

                if (scrollProvider.VerticalScrollPercent == 100)
                {
                    direction = ScrollAmount.SmallDecrement;
                }
                if (direction == ScrollAmount.SmallDecrement && scrollProvider.VerticalScrollPercent == 0)
                {
                    throw new NotSupportedException(ResourcesLocal3.Instance.ErrorNotFoundItem);
                }
                scrollProvider.Scroll(ScrollAmount.NoAmount, direction);
                InvokeUtility.DoEvents();
            }
        }
示例#2
0
        internal static ContextMenu OpenMenu(UIElement target, bool openByKey, out Clean cleaner)
        {
            cleaner = null;

            FrameworkElement owner = null;
            var tree = TreeUtilityInTarget.VisualTree(target, TreeRunDirection.Ancestors);

            foreach (var e in tree)
            {
                var f = e as FrameworkElement;
                if (f != null && f.ContextMenu != null)
                {
                    owner = f;
                    break;
                }
            }
            if (owner == null)
            {
                throw new NotSupportedException();
            }
            var menu = owner.ContextMenu;

            if (openByKey)
            {
                target.Focus();
                SendInputEx.SendKey(System.Windows.Forms.Keys.Apps);
            }
            else
            {
                int count = menu.CommandBindings.Count;

                foreach (var e in TreeUtilityInTarget.VisualTree(target, TreeRunDirection.Ancestors))
                {
                    var u = e as UIElement;
                    if (u != null && u.CommandBindings != null)
                    {
                        foreach (CommandBinding command in u.CommandBindings)
                        {
                            menu.CommandBindings.Add(command);
                        }
                    }
                }
                target.Focus();
                menu.IsOpen = true;
                InvokeUtility.DoEvents();

                //数を元に戻す
                cleaner = () =>
                {
                    while (count < menu.CommandBindings.Count)
                    {
                        menu.CommandBindings.RemoveAt(menu.CommandBindings.Count - 1);
                    }
                    menu.IsOpen = false;
                };
            }

            return(menu);
        }
        static void EmulateClick(MenuItem item)
        {
            IInvokeProvider invoker = new MenuItemAutomationPeer(item);

            item.Focus();
            invoker.Invoke();
            InvokeUtility.DoEvents();
        }
示例#4
0
        static void ShowNextItem(TreeViewItem item)
        {
            var peer = new TreeViewItemAutomationPeer(item);
            IExpandCollapseProvider expander = peer;

            expander.Expand();
            InvokeUtility.DoEvents();
        }
        static void EmulateClick(MenuItem item, WPFContextMenu.Clean clean)
        {
            IInvokeProvider invoker = new MenuItemAutomationPeer(item);

            item.Focus();
            invoker.Invoke();
            InvokeUtility.DoEvents();
            clean();
        }
示例#6
0
        static TreeViewItem GetItemAndScrollIntoView(TreeView tree, ItemsControl parent, int i)
        {
            var box = VisualTreeHelper.GetDescendantBounds(tree);

            var peer           = ItemsControlAutomationPeer.CreatePeerForElement(tree);
            var scrollProvider = peer.GetPattern(PatternInterface.Scroll) as IScrollProvider;
            var direction      = ScrollAmount.SmallIncrement;

            bool min1 = false;
            bool max1 = false;

            while (true)
            {
                var item = parent.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
                if (item != null)
                {
                    item.BringIntoView();
                    InvokeUtility.DoEvents();
                    var top = item.TranslatePoint(new Point(), tree);
                    if (box.Contains(new Point(box.X, top.Y + item.ActualHeight / 2)))
                    {
                        return(item);
                    }
                }

                if (scrollProvider.VerticalScrollPercent == 100)
                {
                    if (max1)
                    {
                        direction = ScrollAmount.SmallDecrement;
                    }
                    else
                    {
                        max1 = true;
                    }
                }
                if (direction == ScrollAmount.SmallDecrement && scrollProvider.VerticalScrollPercent == 0)
                {
                    if (min1)
                    {
                        if (item != null)
                        {
                            return(item);
                        }
                        throw new NotSupportedException(ResourcesLocal3.Instance.ErrorNotFoundItem);
                    }
                    else
                    {
                        min1 = true;
                    }
                }

                if (!scrollProvider.VerticallyScrollable)
                {
                    if (item != null)
                    {
                        return(item);
                    }
                }

                scrollProvider.Scroll(ScrollAmount.NoAmount, direction);
                InvokeUtility.DoEvents();
            }
        }