-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Added automation peers for BladeView and BladeItem controls #3518
Merged
michael-hawker
merged 10 commits into
master
from
jamesmcroft/3517-bladeview-automation
Dec 15, 2020
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6ebb1c6
Added automation peers for BladeView and BladeItem controls
jamesmcroft b7988ae
Updated incorrect doc header for GetNameCore on BladeItemAutomationPeer
jamesmcroft 13db2dd
Merge branch 'master' into jamesmcroft/3517-bladeview-automation
Rosuavio ef2d15d
Fixed using directives in BladeView automation changes
jamesmcroft 795993f
Merge branch 'jamesmcroft/3517-bladeview-automation' of https://githu…
jamesmcroft 2e3e9c2
Merge branch 'master' into jamesmcroft/3517-bladeview-automation
Rosuavio d3a5ade
Merge branch 'master' into jamesmcroft/3517-bladeview-automation
jamesmcroft e2d9e93
Updated BladeView and BladeItem
jamesmcroft ad1800a
Added change to include blade item header as potential GetNameCore re…
jamesmcroft 32e3c4b
Merge branch 'master' into jamesmcroft/3517-bladeview-automation
Rosuavio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// 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 System.Linq; | ||
using Microsoft.Toolkit.Uwp.UI.Controls; | ||
using Windows.UI.Xaml.Automation.Peers; | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers | ||
{ | ||
/// <summary> | ||
/// Defines a framework element automation peer for the <see cref="BladeItem"/>. | ||
/// </summary> | ||
public class BladeItemAutomationPeer : FrameworkElementAutomationPeer | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BladeItemAutomationPeer"/> class. | ||
/// </summary> | ||
/// <param name="owner"> | ||
/// The <see cref="BladeItem" /> that is associated with this <see cref="T:Windows.UI.Xaml.Automation.Peers.BladeItemAutomationPeer" />. | ||
/// </param> | ||
public BladeItemAutomationPeer(BladeItem owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
private BladeItem OwnerBladeItem | ||
{ | ||
get { return this.Owner as BladeItem; } | ||
} | ||
|
||
/// <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 BladeItem | ||
/// - BladeItem class name | ||
/// </returns> | ||
protected override string GetNameCore() | ||
{ | ||
int? index = this.OwnerBladeItem.ParentBladeView.GetBladeItems().ToList().IndexOf(this.OwnerBladeItem); | ||
|
||
string name = base.GetNameCore(); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return $"{name} {index}"; | ||
} | ||
|
||
if (this.OwnerBladeItem != null && !string.IsNullOrEmpty(this.OwnerBladeItem.Name)) | ||
{ | ||
return this.OwnerBladeItem.Name; | ||
michael-hawker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (string.IsNullOrEmpty(name)) | ||
{ | ||
name = this.GetClassName(); | ||
} | ||
|
||
return $"{name} {index}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// 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 System.Collections.Generic; | ||
using Microsoft.Toolkit.Uwp.UI.Controls; | ||
using Windows.UI.Xaml.Automation.Peers; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers | ||
{ | ||
/// <summary> | ||
/// Defines a framework element automation peer for the <see cref="BladeView"/> control. | ||
/// </summary> | ||
public class BladeViewAutomationPeer : ItemsControlAutomationPeer | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BladeViewAutomationPeer"/> class. | ||
/// </summary> | ||
/// <param name="owner"> | ||
/// The <see cref="BladeView" /> that is associated with this <see cref="T:Windows.UI.Xaml.Automation.Peers.BladeViewAutomationPeer" />. | ||
/// </param> | ||
public BladeViewAutomationPeer(BladeView owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
private BladeView OwningBladeView | ||
{ | ||
get | ||
{ | ||
return Owner as BladeView; | ||
} | ||
} | ||
|
||
/// <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 BladeView | ||
/// - BladeView class name | ||
/// </returns> | ||
protected override string GetNameCore() | ||
{ | ||
string name = base.GetNameCore(); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
if (this.OwningBladeView != null) | ||
{ | ||
name = this.OwningBladeView.Name; | ||
michael-hawker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (string.IsNullOrEmpty(name)) | ||
{ | ||
name = this.GetClassName(); | ||
} | ||
|
||
return name; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the collection of elements that are represented in the UI Automation tree as immediate | ||
/// child elements of the automation peer. | ||
/// </summary> | ||
/// <returns>The children elements.</returns> | ||
protected override IList<AutomationPeer> GetChildrenCore() | ||
{ | ||
BladeView owner = OwningBladeView; | ||
|
||
ItemCollection items = owner.Items; | ||
if (items.Count <= 0) | ||
{ | ||
return null; | ||
} | ||
|
||
List<AutomationPeer> peers = new List<AutomationPeer>(items.Count); | ||
for (int i = 0; i < items.Count; i++) | ||
{ | ||
if (owner.ContainerFromIndex(i) is BladeItem element) | ||
{ | ||
peers.Add(FromElement(element) ?? CreatePeerForElement(element)); | ||
} | ||
} | ||
|
||
return peers; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably add 1 to the index so the blades will be named "blade 1", "blade 2",.. instead of "blade 0", "blade 1",... This will be more "natural" for the users.