-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Added automation peer class for expander #3504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
b2e65e2
9b17e3d
439cf3d
43df5ba
e5e70be
5560452
41b28b2
b74914a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Windows.UI.Xaml.Automation; | ||
| using Windows.UI.Xaml.Automation.Peers; | ||
| using Windows.UI.Xaml.Automation.Provider; | ||
|
|
||
| namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
| { | ||
| /// <summary> | ||
| /// Defines a framework element automation peer for the <see cref="Expander"/> control. | ||
| /// </summary> | ||
| public class ExpanderAutomationPeer : FrameworkElementAutomationPeer, IToggleProvider | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jamesmcroft I missed we should have used the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me take a look, I don't see why not though. Would you want this to be inclusive of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jamesmcroft good question. I don't know if it's a problem to provide multiple interfaces, probably best to include both if possible? I know some other code will probably look for one over the other, so I imagine having both would allow it to be used by the most other code parts looking for certain types of peers. @chingucoding @ranjeshj any thoughts? Would it make sense to add unit tests like in #3544 as well?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I would argue that having both interfaces only makes sense if you expose both patterns in
Yes, I think testing that peer and the exposed functions of the peer should be done.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can have multiple patterns supported for sure. ExpandCollapse pattern made sense for Expander.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jamesmcroft if you've got some cycles still to continue helping with this, mind submitting a follow-on PR with the tweaks? Thanks!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michael-hawker I'll get another PR open for these changes 😄 |
||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ExpanderAutomationPeer"/> class. | ||
| /// </summary> | ||
| /// <param name="owner"> | ||
| /// The <see cref="Expander" /> that is associated with this <see cref="T:Windows.UI.Xaml.Automation.Peers.ExpanderAutomationPeer" />. | ||
| /// </param> | ||
| public ExpanderAutomationPeer(Expander owner) | ||
| : base(owner) | ||
| { | ||
| } | ||
|
|
||
| /// <summary>Gets the toggle state of the control.</summary> | ||
| /// <returns>The toggle state of the control, as a value of the enumeration.</returns> | ||
| public ToggleState ToggleState => OwningExpander.IsExpanded ? ToggleState.On : ToggleState.Off; | ||
|
|
||
| private Expander OwningExpander | ||
| { | ||
| get | ||
| { | ||
| return Owner as Expander; | ||
| } | ||
| } | ||
|
|
||
| /// <summary>Cycles through the toggle states of a control.</summary> | ||
| public void Toggle() | ||
| { | ||
| if (!IsEnabled()) | ||
| { | ||
| throw new ElementNotEnabledException(); | ||
| } | ||
|
|
||
| OwningExpander.IsExpanded = !OwningExpander.IsExpanded; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the control type for the element that is associated with the UI Automation peer. | ||
| /// </summary> | ||
| /// <returns>The control type.</returns> | ||
| protected override AutomationControlType GetAutomationControlTypeCore() | ||
| { | ||
| return AutomationControlType.Custom; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType, | ||
| /// differentiates the control represented by this AutomationPeer. | ||
| /// </summary> | ||
| /// <returns>The string that contains the name.</returns> | ||
| protected override string GetClassNameCore() | ||
| { | ||
| return Owner.GetType().Name; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Called by GetName. | ||
| /// </summary> | ||
| /// <returns> | ||
| /// Returns the first of these that is not null or empty: | ||
| /// - Value returned by the base implementation | ||
| /// - Name of the owning Expander | ||
| /// - Expander class name | ||
| /// </returns> | ||
| protected override string GetNameCore() | ||
| { | ||
| string name = base.GetNameCore(); | ||
| if (!string.IsNullOrEmpty(name)) | ||
| { | ||
| return name; | ||
| } | ||
|
|
||
| if (this.OwningExpander != null) | ||
| { | ||
| name = this.OwningExpander.Name; | ||
| } | ||
|
|
||
| if (string.IsNullOrEmpty(name)) | ||
| { | ||
| name = this.GetClassName(); | ||
| } | ||
|
|
||
| return name; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the control pattern that is associated with the specified Windows.UI.Xaml.Automation.Peers.PatternInterface. | ||
| /// </summary> | ||
| /// <param name="patternInterface">A value from the Windows.UI.Xaml.Automation.Peers.PatternInterface enumeration.</param> | ||
| /// <returns>The object that supports the specified pattern, or null if unsupported.</returns> | ||
| protected override object GetPatternCore(PatternInterface patternInterface) | ||
| { | ||
| switch (patternInterface) | ||
| { | ||
| case PatternInterface.Toggle: | ||
| return this; | ||
| } | ||
|
|
||
| return base.GetPatternCore(patternInterface); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.