예제 #1
0
        public static void SetChecked(this AutomationElement parent, string name, bool value)
        {
            AutomationElement box = parent.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name));

            if (box == null)
            {
                throw new Exception("CheckBox '" + name + "' not found");
            }
            if (!box.Current.IsEnabled)
            {
                throw new Exception("CheckBox '" + name + "' is not enabled");
            }

            TogglePattern p = (TogglePattern)box.GetCurrentPattern(TogglePattern.Pattern);

            if (value)
            {
                if (p.Current.ToggleState != ToggleState.On)
                {
                    p.Toggle();
                }
            }
            else
            {
                if (p.Current.ToggleState == ToggleState.On)
                {
                    p.Toggle();
                }
            }
        }
예제 #2
0
 protected override void ProcessRecord()
 {
     if (UIElement != null)
     {
         UIElement.SetFocus();
         TogglePattern tp = GetPattern.GetTogglePattern(UIElement);
         if ((!On.ToBool() && !Off.ToBool()) || (On.ToBool() && Off.ToBool()))
         {
             tp.Toggle();
         }
         else if (Off.ToBool())
         {
             while (tp.Current.ToggleState != ToggleState.Off && Timeout > 0)
             {
                 tp.Toggle();
                 Thread.Sleep(1000);
                 Timeout = Timeout - 1000;
             }
         }
         else if (On.ToBool())
         {
             while (tp.Current.ToggleState != ToggleState.On && Timeout > 0)
             {
                 tp.Toggle();
                 Thread.Sleep(1000);
                 Timeout = Timeout - 1000;
             }
         }
     }
 }
예제 #3
0
        public void TogglePatternTest()
        {
            using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL main.cpl ,2"))
            {
                // Find a well-known checkbox
                AutomationElement checkbox = host.Element.FindFirst(TreeScope.Subtree,
                                                                    new PropertyCondition(AutomationElement.AutomationIdProperty, "109"));
                Assert.IsNotNull(checkbox);

                TogglePattern toggle        = (TogglePattern)checkbox.GetCurrentPattern(TogglePattern.Pattern);
                ToggleState   originalState = toggle.Current.ToggleState;
                toggle.Toggle();
                // Slight wait for effect
                System.Threading.Thread.Sleep(100 /* ms */);
                ToggleState currentState = toggle.Current.ToggleState;
                Assert.AreNotEqual(originalState, currentState);

                // Put it back
                while (currentState != originalState)
                {
                    toggle.Toggle();
                    System.Threading.Thread.Sleep(100 /* ms */);
                    currentState = toggle.Current.ToggleState;
                }
            }
        }
예제 #4
0
        private static void executePattern(AutomationElement subject, AutomationPattern inPattern)
        {
            switch (inPattern.ProgrammaticName)
            {
            case "InvokePatternIdentifiers.Pattern":
            {
                InvokePattern invoke = (InvokePattern)subject.GetCurrentPattern(InvokePattern.Pattern);
                invoke.Invoke();
                break;
            }

            case "SelectionItemPatternIdentifiers.Pattern":
            {
                SelectionItemPattern select = (SelectionItemPattern)subject.GetCurrentPattern(SelectionItemPattern.Pattern);
                select.Select();
                break;
            }

            case "TogglePatternIdentifiers.Pattern":
            {
                TogglePattern toggle = (TogglePattern)subject.GetCurrentPattern(TogglePattern.Pattern);
                toggle.Toggle();
                break;
            }

            case "ExpandCollapsePatternIdentifiers.Pattern":
            {
                ExpandCollapsePattern exColPat = (ExpandCollapsePattern)subject.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                exColPat.Expand();
                break;
            }
            }
        }
        public static void Toggle(this AutomationElement Control)
        {
            //check if the buttonControl is indeed a handle to a button-based control
            TogglePattern togglePattern = ValidateControlForTogglePattern(Control);

            //click the button control
            togglePattern.Toggle();
        }
예제 #6
0
 public void Toggle()
 {
     STAHelper.Invoke(
         delegate() {
         TogglePattern.Toggle();
     }
         );
 }
예제 #7
0
 static void Game_OnGameLoad(EventArgs args)
 {
     Game.PrintChat("AssemblySelector loaded!");
     Config = new Menu("ExeSelect", "AssemblySelector", true);
     Config.AddToMainMenu();
     new Thread(() =>
     {
         AutomationElement desktop         = AutomationElement.RootElement;
         AutomationElement leaguesharp     = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "LeagueSharp"));
         AutomationElement assemblyTab     = leaguesharp.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "TabControl"));
         AutomationElement assemblyTabItem = assemblyTab.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Assemblies"));
         AutomationElement assemblyGrid    = assemblyTabItem.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "DataGrid"));
         Boolean allAssemblies             = false;
         int i = 0;
         Game.PrintChat(leaguesharp.Current.Name);
         while (!allAssemblies)
         {
             AutomationElement assemblyName = ((GridPattern)assemblyGrid.GetCurrentPattern(GridPattern.Pattern)).GetItem(i, 1);
             if (assemblyName == null)
             {
                 break;
             }
             AutomationElement assemblyType = ((GridPattern)assemblyGrid.GetCurrentPattern(GridPattern.Pattern)).GetItem(i, 2);
             if (assemblyType.Current.Name.Contains("Executable"))
             {
                 AutomationElement checkBoxElement = ((GridPattern)assemblyGrid.GetCurrentPattern(GridPattern.Pattern)).GetItem(i, 0).FindFirst(TreeScope.Children, Condition.TrueCondition);
                 TogglePattern checkBox            = (TogglePattern)checkBoxElement.GetCurrentPattern(TogglePattern.Pattern);
                 Boolean init = false;
                 if (checkBox.Current.ToggleState == ToggleState.On)
                 {
                     init = true;
                 }
                 MenuItem assemblyItem = Config.AddItem(new MenuItem(assemblyName.Current.Name, assemblyName.Current.Name).SetValue <bool>(init));
                 assemblyList.Add(assemblyName.Current.Name, checkBox);
                 assemblyItem.ValueChanged += (s, e) =>
                 {
                     try
                     {
                         Console.WriteLine(((MenuItem)s).Name);
                         new Thread(() =>
                         {
                             Thread.Sleep(500);
                             if (assemblyList[((MenuItem)s).Name].Current.ToggleState == ToggleState.Off && e.GetNewValue <Boolean>() ||
                                 assemblyList[((MenuItem)s).Name].Current.ToggleState == ToggleState.On && !e.GetNewValue <Boolean>())
                             {
                                 assemblyList[((MenuItem)s).Name].Toggle();
                             }
                         }).Start();
                     }
                     catch
                     {
                     }
                 };
             }
             i++;
         }
     }).Start();
 }
예제 #8
0
        public void AutoResize_Default()
        {
            try
            {
                Console.WriteLine("starting test....");
                AutomationElement autoResize        = GetElement("chkAutoResize");
                AutomationElement txtWidthReadOnly  = GetElement("txtWidthReadOnly");
                AutomationElement txtWidthWrite     = GetElement("txtWidthWrite");
                AutomationElement txtHeightReadOnly = GetElement("txtHeightReadOnly");
                AutomationElement txtHeightWrite    = GetElement("txtHeightWrite");

                TogglePattern toggle = (TogglePattern)autoResize.GetCurrentPattern(TogglePattern.Pattern);

                //verify is off at startup
                Assert.AreEqual(ToggleState.Off, toggle.Current.ToggleState);

                //verify widthRO is not visible and widthWrite is
                Assert.IsFalse((bool)txtWidthWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsTrue((bool)txtWidthReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //verify heightRO is not visible and heightWrite is
                Assert.IsFalse((bool)txtHeightWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsTrue((bool)txtHeightReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //can't check canvas size now need to refactor

                //verify the value
                ValuePattern txtWidthValue  = (ValuePattern)txtWidthWrite.GetCurrentPattern(ValuePattern.Pattern);
                ValuePattern txtHeightValue = (ValuePattern)txtHeightWrite.GetCurrentPattern(ValuePattern.Pattern);
                int          width          = Int32.Parse(txtWidthValue.Current.Value);
                int          height         = Int32.Parse(txtHeightValue.Current.Value);

                Assert.AreEqual(DEFAULT_WIDTH, width);
                Assert.AreEqual(DEFAULT_HEIGHT, height);

                toggle.Toggle();

                //verify widthRO is visible and widthWrite is not
                Assert.IsTrue((bool)txtWidthWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsFalse((bool)txtWidthReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //verify heightRO is visible and heightWrite is not
                Assert.IsTrue((bool)txtHeightWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsFalse((bool)txtHeightReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //verify the value
                width  = Int32.Parse(txtWidthReadOnly.Current.Name);
                height = Int32.Parse(txtHeightReadOnly.Current.Name);
                Assert.AreEqual(DEFAULT_WIDTH, width);
                Assert.AreEqual(DEFAULT_HEIGHT, height);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception Caught:");
                Console.WriteLine(e.Message);
                Assert.Fail();
            }
        }
        // RopModifyPermissions RopGetPermissionsTable
        public void ModifyFolderPermissions()
        {
            // Get account name
            var desktop   = AutomationElement.RootElement;
            var nameSpace = oApp.GetNamespace("MAPI");

            Outlook.MAPIFolder folder   = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            string             userName = folder.Parent.Name;

            // Get outlook window
            var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook");
            var window_outlook    = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10);

            // Get Folder Tab and select it
            Condition            cd_RibbonTabs      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem), new PropertyCondition(AutomationElement.NameProperty, "Folder"));
            AutomationElement    item_RibbonTabs    = Utilities.WaitForElement(window_outlook, cd_RibbonTabs, TreeScope.Descendants, 300);
            SelectionItemPattern Pattern_RibbonTabs = (SelectionItemPattern)item_RibbonTabs.GetCurrentPattern(SelectionItemPattern.Pattern);

            Pattern_RibbonTabs.Select();

            // Get "Folder Permissions" and select it
            Condition         cd_FolderPermissions           = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Folder Permissions"));
            AutomationElement item_FolderPermissions         = Utilities.WaitForElement(window_outlook, cd_FolderPermissions, TreeScope.Descendants, 10);
            InvokePattern     clickPattern_FolderPermissions = (InvokePattern)item_FolderPermissions.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_FolderPermissions.Invoke();

            // Get "Inbox Properties" window
            var condition_permission = new PropertyCondition(AutomationElement.NameProperty, "Inbox Properties");
            var window_FolderProp    = Utilities.WaitForElement(window_outlook, condition_permission, TreeScope.Children, 10);

            // Get and select "Create items"
            Condition         cd_write      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox), new PropertyCondition(AutomationElement.NameProperty, "Edit all"));
            AutomationElement item_write    = Utilities.WaitForElement(window_FolderProp, cd_write, TreeScope.Descendants, 10);
            TogglePattern     Pattern_write = (TogglePattern)item_write.GetCurrentPattern(TogglePattern.Pattern);

            Pattern_write.Toggle();

            // Click OK in Microsoft Outlook dialog box
            var           condition_Dailog      = new PropertyCondition(AutomationElement.NameProperty, "Microsoft Outlook");
            var           window_Dailog         = Utilities.WaitForElement(window_FolderProp, condition_Dailog, TreeScope.Children, 10);
            var           condition_DailogOK    = new PropertyCondition(AutomationElement.AutomationIdProperty, "6");
            var           item_DailogOK         = Utilities.WaitForElement(window_Dailog, condition_DailogOK, TreeScope.Children, 10);
            InvokePattern clickPattern_DailogOK = (InvokePattern)item_DailogOK.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_DailogOK.Invoke();

            // Click OK in "Inbox Properties" window
            var           condition_FolderPropOK        = new PropertyCondition(AutomationElement.AutomationIdProperty, "1");
            var           item_FolderPropertyOK         = Utilities.WaitForElement(window_FolderProp, condition_FolderPropOK, TreeScope.Children, 10);
            InvokePattern clickPattern_FolderPropertyOK = (InvokePattern)item_FolderPropertyOK.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_FolderPropertyOK.Invoke();

            bool result = MessageParser.ParseMessage();

            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
예제 #10
0
        private void TogglePatternController()
        {
            TogglePattern togglePattern = (TogglePattern)PatternObject;

            if (MethodType == 1)
            {
                togglePattern.Toggle();
            }
        }
예제 #11
0
        public static void Check(AutomationElement element)
        {
            // element.SetFocus();
            //SendKeys.SendWait(" ");

            TogglePattern togglePattern = element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;

            togglePattern.Toggle();
        }
예제 #12
0
파일: Button.cs 프로젝트: nicetester/Sirius
        public bool IsIntermediate(int hwnd)
        {
            AutomationElement element = Find(hwnd);
            TogglePattern     toggle  = element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;

            logger.Debug("");
            return(EnumExtensions.HasFlag(toggle.Current.ToggleState, ToggleState.Indeterminate));
            //return toggle.Current.ToggleState.HasFlag(ToggleState.Indeterminate);
        }
 /// <summary>
 /// Sets state of toggle control
 /// </summary>
 /// <param name="control">The UI Automation element</param>
 /// <param name="toggleState">The current <see cref="System.Windows.Automation.ToggleState"/>ToggleState</param>
 internal static void SetToggleState(AutomationElement control, ToggleState toggleState)
 {
     /* Only need to change it if it needs-a-changin' */
     if (GetToggleState(control) != toggleState)
     {
         TogglePattern pattern = (TogglePattern)control.GetCurrentPattern(TogglePattern.Pattern);
         pattern.Toggle();
     }
     ValueVerifier <ToggleState, ToggleState> .Verify(toggleState, GetToggleState(control));
 }
예제 #14
0
        public static bool xtGetCheckedState(this AutomationElement element)
        {
            bool IsChecked;

            _TogglePattern = Retry.For(() =>
                                       ((TogglePattern)element.GetCurrentPattern(TogglePattern.Pattern)),
                                       TimeSpan.FromSeconds(10));

            return(IsChecked = _TogglePattern.Current.ToggleState == ToggleState.On);
        }
예제 #15
0
        // This will bring the window to front if it is in normal or maximized state. Using Win32 Click instead
        public static void ChangeCheckBoxState(AutomationElement element)
        {
            TogglePattern targetInvokePattern = element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;

            if (targetInvokePattern == null)
            {
                return;
            }
            targetInvokePattern.Toggle();
        }
예제 #16
0
파일: Button.cs 프로젝트: nicetester/Sirius
 public void SetCheck(int hwnd, bool check)
 {
     if (IsChecked(hwnd) != check)
     {
         AutomationElement element = Find(hwnd);
         TogglePattern     toggle  = element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
         logger.Debug("");
         toggle.Toggle();
     }
 }
예제 #17
0
        public static bool TryGetTogglePattern(this AutomationElement element, out TogglePattern result)
        {
            if (element.TryGetCurrentPattern(System.Windows.Automation.TogglePattern.Pattern, out var pattern))
            {
                result = (TogglePattern)pattern;
                return(true);
            }

            result = null;
            return(false);
        }
예제 #18
0
        public void Toggle(bool log)
        {
            if (log)
            {
                procedureLogger.Action(string.Format("Toggle {0}.", this.NameAndType));
            }

            TogglePattern tp = (TogglePattern)element.GetCurrentPattern(TogglePattern.Pattern);

            tp.Toggle();
        }
예제 #19
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        protected TogglePatternWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
            :
            base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
        {
            _pattern = (TogglePattern)element.GetCurrentPattern(TogglePattern.Pattern);

            if (_pattern == null)
            {
                throw new Exception("TogglePattern: " + Helpers.PatternNotSupported);
            }
        }
예제 #20
0
        public void ToggleTest()
        {
            TogglePattern pattern = (TogglePattern)checkBox1Element.GetCurrentPattern(TogglePattern.Pattern);

            Assert.AreEqual(ToggleState.Off, pattern.Current.ToggleState, "ToggleState before Toggle");
            pattern.Toggle();
            // TODO: Enable this after resolving at-spi-sharp threading/MainLoop issues
            if (!Atspi)
            {
                Assert.AreEqual(ToggleState.On, pattern.Current.ToggleState, "ToggleState after Toggle");
            }
        }
예제 #21
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public string ToggleState()
 {
     try
     {
         TogglePattern t = (TogglePattern)elePara.GetMe().GetCurrentPattern(TogglePattern.Pattern);
         return(t.Current.ToggleState.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("Failed to get isSelected status. {0}", ex));
     }
 }
예제 #22
0
        //</Snippet1100>

        ///--------------------------------------------------------------------
        /// <summary>
        /// Handles the Toggle click event.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        ///--------------------------------------------------------------------
        void Toggle_Click(object sender, RoutedEventArgs e)
        {
            Button        clientButton = sender as Button;
            TogglePattern t            = clientButton.Tag as TogglePattern;

            if (t == null)
            {
                return;
            }
            t.Toggle();
            statusText.Text = "Element toggled " + t.Current.ToggleState.ToString();
        }
예제 #23
0
        public static bool toggleCheckbox(AutomationElement ae)
        {
            object temp;

            if (ae.TryGetCurrentPattern(TogglePattern.Pattern, out temp))
            {
                TogglePattern pattern = temp as TogglePattern;
                pattern.Toggle();
                return(true);
            }
            return(false);
        }
예제 #24
0
        // </Snippet101>

        // <Snippet102>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Calls the TogglePattern.Toggle() method for an associated
        /// automation element.
        /// </summary>
        /// <param name="togglePattern">
        /// The TogglePattern control pattern obtained from
        /// an automation element.
        /// </param>
        ///--------------------------------------------------------------------
        private void ToggleElement(TogglePattern togglePattern)
        {
            try
            {
                togglePattern.Toggle();
            }
            catch (InvalidOperationException)
            {
                // object is not able to perform the requested action
                return;
            }
        }
예제 #25
0
        public static bool IsThinLines()
        {
            AutomationElement button = GetThinLinesButton();

            TogglePattern togglePattern
                = button.GetCurrentPattern(
                      TogglePattern.Pattern) as TogglePattern;

            string state = togglePattern.Current
                           .ToggleState.ToString().ToUpper();

            return(state == "ON");
        }
예제 #26
0
        public static bool IsChecked(this AutomationElement parent, string name)
        {
            AutomationElement box = parent.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name));

            if (box == null)
            {
                throw new Exception("CheckBox '" + name + "' not found");
            }

            TogglePattern p = (TogglePattern)box.GetCurrentPattern(TogglePattern.Pattern);

            return(p.Current.ToggleState == ToggleState.On);
        }
예제 #27
0
        public void Interact()
        {
            // For debugging purposes we enlight the control
            // choosen so we can easily spot it.
            //DBGMark();

            // If the element we have is from UIAutomation, simply interact with it.
            object objPattern;

            if (AutoElementRef != null && AutoElementRef.Current.ControlType == System.Windows.Automation.ControlType.Button && AutoElementRef.TryGetCurrentPattern(InvokePattern.Pattern, out objPattern))
            {
                System.Windows.Point pt = new System.Windows.Point();
                if (AutoElementRef.TryGetClickablePoint(out pt))
                {
                    System.Windows.Forms.Cursor.Position = new Point((int)pt.X + 1, (int)pt.Y + 1);
                    LeftClick();
                }
                else
                {
                    // NOTE! The following approach won't work for some strange UIs (probably bugged). We use the classic way of sendkeys to solve this problem once for all
                    // For buttons
                    InvokePattern invPattern = objPattern as InvokePattern;
                    invPattern.Invoke();
                }
            }
            else if (AutoElementRef != null && AutoElementRef.Current.ControlType == System.Windows.Automation.ControlType.RadioButton && AutoElementRef.TryGetCurrentPattern(SelectionItemPatternIdentifiers.Pattern, out objPattern))
            {
                // Radios
                SelectionItemPattern invPattern = objPattern as SelectionItemPattern;
                invPattern.Select();
            }
            else if (AutoElementRef != null && AutoElementRef.Current.ControlType == System.Windows.Automation.ControlType.CheckBox && AutoElementRef.TryGetCurrentPattern(TogglePatternIdentifiers.Pattern, out objPattern))
            {
                // Checkboxes
                TogglePattern invPattern = objPattern as TogglePattern;
                invPattern.Toggle();
            }
            else
            {
                // Let's assume a very simple thing: interaction = mouseclick. We click in the middle of the control.
                // This won't work for combobox, but will work for mostly any Checkbox, radio button, hyperlink and custom buttons.
                // Calculate the center of control
                int x = PositionScreenRelative.Width / 2 + PositionScreenRelative.X;
                int y = PositionScreenRelative.Height / 2 + PositionScreenRelative.Y;

                System.Windows.Forms.Cursor.Position = new Point(x, y);
                LeftClick();
            }
        }
        public void SetUnselected()
        {
            Assert.IsTrue((bool)Element.GetCurrentPropertyValue(AutomationElement.IsTogglePatternAvailableProperty), "Element is not a check box");
            TogglePattern pattern = (TogglePattern)Element.GetCurrentPattern(TogglePattern.Pattern);

            if (pattern.Current.ToggleState != ToggleState.Off)
            {
                pattern.Toggle();
            }
            if (pattern.Current.ToggleState != ToggleState.Off)
            {
                pattern.Toggle();
            }
            Assert.AreEqual(pattern.Current.ToggleState, ToggleState.Off, "Could not toggle " + Name + " to Off.");
        }
예제 #29
0
        public static void Toggle(AutomationElement element, bool toggle)
        {
            TogglePattern currentPattern = AutomationPatternHelper.GetTogglePattern(element);
            ToggleState   indeterminate  = ToggleState.Indeterminate;

            if (toggle == true)
            {
                indeterminate = ToggleState.On;
            }
            else if (toggle == false)
            {
                indeterminate = ToggleState.Off;
            }
            while (currentPattern.Current.ToggleState != indeterminate)
            {
                currentPattern.Toggle();
            }
        }
예제 #30
0
        // </Snippet100>

        // <Snippet101>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Obtains a TogglePattern control pattern from an automation element.
        /// </summary>
        /// <param name="targetControl">
        /// The automation element of interest.
        /// </param>
        /// <returns>
        /// A TogglePattern object.
        /// </returns>
        ///--------------------------------------------------------------------
        private TogglePattern GetTogglePattern(AutomationElement targetControl)
        {
            TogglePattern togglePattern = null;

            try
            {
                togglePattern =
                    targetControl.GetCurrentPattern(TogglePattern.Pattern)
                    as TogglePattern;
            }
            catch (InvalidOperationException)
            {
                // object doesn't support the TogglePattern control pattern
                return(null);
            }

            return(togglePattern);
        }