예제 #1
0
        public MainWindow()
        {
            InitializeComponent();

            CmdStart.IsEnabled = true;
            CmdStop.IsEnabled = false;
            CmdRestart.IsEnabled = false;

            Closing += CloseWindow;

            var writer = new StreamWriter(System.Console.OpenStandardOutput());

            var autoCmdStart = new MenuItemAutomationPeer(CmdStart);
            var invokeProvider = autoCmdStart.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
            invokeProvider.Invoke();
        }
        static void GetIndices(IEnumerable<MenuItem> items, string[] headerTexts, int[] indices, int index)
        {
            int i = 0;
            foreach (var e in items)
            {
                if (e.Header.ToString() == headerTexts[index])
                {
                    indices[index] = i;
                    if (index == indices.Length - 1)
                    {
                        return;
                    }

                    //次のメニューを開く
                    IInvokeProvider invoker = new MenuItemAutomationPeer(e);
                    invoker.Invoke();

                    foreach (var popup in SearcherInTarget.ByType<Popup>(TreeUtilityInTarget.VisualTree(e)))
                    {
                        GetIndices(SearcherInTarget.ByType<MenuItem>(TreeUtilityInTarget.VisualTree(popup.Child)), headerTexts, indices, index + 1);
                        return;
                    }
                    break;
                }
                i++;
            }
            throw new NotSupportedException(ResourcesLocal3.Instance.ErrorNotFoundItem);
        }
 static void EmulateClick(MenuItem item, WPFContextMenu.Clean clean)
 {
     IInvokeProvider invoker = new MenuItemAutomationPeer(item);
     item.Focus();
     invoker.Invoke();
     InvokeUtility.DoEvents();
     clean();
 }
 static void ShowNextItem(MenuItem item)
 {
     IInvokeProvider invoker = new MenuItemAutomationPeer(item);
     invoker.Invoke();
 }
 static int GetItemCount(MenuItem item)
 {
     IInvokeProvider invoker = new MenuItemAutomationPeer(item);
     invoker.Invoke();
     foreach (var p in SearcherInTarget.ByType<Popup>(TreeUtilityInTarget.VisualTree(item)))
     {
         int count = 0;
         foreach (var e in SearcherInTarget.ByType<MenuItem>(TreeUtilityInTarget.VisualTree(p.Child)))
         {
             count++;
         }
         return count;
     }
     return 0;
 }