internal void RaiseExpandCollapseStatePropertyChangedEvent(ExpandCollapseState oldValue, ExpandCollapseState newValue)
 {
     if (oldValue != newValue)
     {
         RaisePropertyChangedEvent(ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty, oldValue, newValue);
     }
 }
Пример #2
0
        /// ---------------------------------------------------------------
        /// <summary>
        /// Will call the approprate ExpandCollapse state to happen
        /// </summary>
        /// ---------------------------------------------------------------
        void expandCollapseMenu(ExpandCollapseState desiredState)
        {
            ExpandCollapsePattern ecp = this.AutomationElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            _desiredState = desiredState;

            if (ecp == null)
                throw new InvalidOperationException("The element does not support ExpandCallapsePattern");

            _ev.Reset();

            Automation.AddAutomationPropertyChangedEventHandler(
                _element, 
                TreeScope.Element,
                new AutomationPropertyChangedEventHandler(ExpandCollapseEventHandler),
                new AutomationProperty[] { ExpandCollapsePattern.ExpandCollapseStateProperty });

            // Cause the state to happen
            switch (desiredState)
            {
                case ExpandCollapseState.Collapsed:
                    ecp.Collapse();
                    break;

                case ExpandCollapseState.Expanded:
                    /* changing to new flexible logging */
                    //Logger.LogComment("Expanding " + _element.Current.Name);
                    UIVerifyLogger.LogComment("Expanding " + _element.Current.Name);


                    // There can be times when there is already another menu opened and 
                    // we throw an expection, which will dismiss it, do it again.
                    try
                    {
                        ecp.Expand();
                    }
                    catch (Exception exception)
                    {
						if (Library.IsCriticalException(exception))
                            throw;

                        ecp.Expand();
                    }
                    break;

                case ExpandCollapseState.LeafNode:
                    throw new NotImplementedException();

                case ExpandCollapseState.PartiallyExpanded:
                    throw new NotImplementedException();

                default:
                    throw new Exception("Have not implemented case for " + desiredState);

            }

            _ev.WaitOne(10000, false);

            while (ecp.Current.ExpandCollapseState != desiredState)
            {
                throw new Exception("ExpandCollapsePattern.ExpandCollapseStateProperty != " + desiredState.ToString());
            }
        }