// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Diagnostics.CodeAnalysis; using System.Windows.Automation; using System.Windows.Automation.Peers; using System.Windows.Automation.Provider; namespace Microsoft.Management.UI.Internal { /// /// Provides an automation peer for . /// [SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")] public class ExpanderButtonAutomationPeer : ToggleButtonAutomationPeer, IExpandCollapseProvider { #region Fields private ExpanderButton expanderButton; #endregion #region Structors /// /// Initializes a new instance of the class. /// /// The owner of the automation peer. public ExpanderButtonAutomationPeer(ExpanderButton owner) : base(owner) { this.expanderButton = owner; } #endregion #region Overrides /// /// Gets the class name. /// /// The class name. protected override string GetClassNameCore() { return this.Owner.GetType().Name; } /// /// Gets the control pattern for the that is associated with this . /// /// Specifies the control pattern that is returned. /// The control pattern for the that is associated with this . public override object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.ExpandCollapse || patternInterface == PatternInterface.Toggle) { return this; } return null; } #endregion #region IExpandCollapseProvider Implementations /// /// Gets the expand/collapse state of this instance. /// ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState { get { if (this.expanderButton.IsChecked == true) { return ExpandCollapseState.Expanded; } else { return ExpandCollapseState.Collapsed; } } } /// /// Expands this instance of . /// void IExpandCollapseProvider.Expand() { if (!this.IsEnabled()) { throw new ElementNotEnabledException(); } this.expanderButton.IsChecked = true; } /// /// Collapses this instance of . /// void IExpandCollapseProvider.Collapse() { if (!this.IsEnabled()) { throw new ElementNotEnabledException(); } this.expanderButton.IsChecked = false; } #endregion } }