-
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 all 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
163 changes: 163 additions & 0 deletions
163
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,163 @@ | ||
// 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 Microsoft.Toolkit.Uwp.UI.Controls; | ||
using Microsoft.Toolkit.Uwp.UI.Extensions; | ||
using Windows.UI.Xaml.Automation; | ||
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="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.ListItem; | ||
} | ||
|
||
/// <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() | ||
{ | ||
string name = AutomationProperties.GetName(this.OwnerBladeItem); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
name = this.OwnerBladeItem.Name; | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
name = this.OwnerBladeItem.Header?.ToString(); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
TextBlock textBlock = this.OwnerBladeItem.FindDescendant<TextBlock>(); | ||
if (textBlock != null) | ||
{ | ||
return textBlock.Text; | ||
} | ||
|
||
name = base.GetNameCore(); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Called by GetAutomationId that gets the **AutomationId** of the element that is associated with the automation peer. | ||
/// </summary> | ||
/// <returns> | ||
/// The string that contains the automation ID. | ||
/// </returns> | ||
protected override string GetAutomationIdCore() | ||
{ | ||
string automationId = base.GetAutomationIdCore(); | ||
if (!string.IsNullOrEmpty(automationId)) | ||
{ | ||
return automationId; | ||
} | ||
|
||
if (this.OwnerBladeItem != null) | ||
{ | ||
return this.GetNameCore(); | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the size of the set where the element that is associated with the automation peer is located. | ||
/// </summary> | ||
/// <returns> | ||
/// The size of the set. | ||
/// </returns> | ||
protected override int GetSizeOfSetCore() | ||
{ | ||
int sizeOfSet = base.GetSizeOfSetCore(); | ||
|
||
if (sizeOfSet != -1) | ||
{ | ||
return sizeOfSet; | ||
} | ||
|
||
BladeItem owner = this.OwnerBladeItem; | ||
BladeView parent = owner.ParentBladeView; | ||
sizeOfSet = parent.Items.Count; | ||
|
||
return sizeOfSet; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the ordinal position in the set for the element that is associated with the automation peer. | ||
/// </summary> | ||
/// <returns> | ||
/// The ordinal position in the set. | ||
/// </returns> | ||
protected override int GetPositionInSetCore() | ||
{ | ||
int positionInSet = base.GetPositionInSetCore(); | ||
|
||
if (positionInSet != -1) | ||
{ | ||
return positionInSet; | ||
} | ||
|
||
BladeItem owner = this.OwnerBladeItem; | ||
BladeView parent = owner.ParentBladeView; | ||
positionInSet = parent.IndexFromContainer(owner); | ||
|
||
return positionInSet; | ||
} | ||
} | ||
} |
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
115 changes: 115 additions & 0 deletions
115
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,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 System.Collections.Generic; | ||
using Microsoft.Toolkit.Uwp.UI.Controls; | ||
using Windows.UI.Xaml.Automation; | ||
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.List; | ||
} | ||
|
||
/// <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 = AutomationProperties.GetName(this.OwningBladeView); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
name = this.OwningBladeView.Name; | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
name = base.GetNameCore(); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
/// <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; | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
@jamesmcroft the
BladeItem.Header
should be the 'Title' of the Blade, do we want to try and explicitly convert that to a string as a first step?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.
Sorted! Apologies for the delay on sorting this out.