From 6ebb1c6a56d9c5530f2942060a01cbfd193e6e56 Mon Sep 17 00:00:00 2001 From: James Croft Date: Sat, 3 Oct 2020 15:28:40 +0100 Subject: [PATCH 1/5] Added automation peers for BladeView and BladeItem controls --- .../BladeView/BladeItem.Properties.cs | 2 + .../BladeView/BladeItem.cs | 11 ++ .../BladeView/BladeItemAutomationPeer.cs | 84 +++++++++++++ .../BladeView/BladeView.cs | 20 ++++ .../BladeView/BladeViewAutomationPeer.cs | 112 ++++++++++++++++++ 5 files changed, 229 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.Properties.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.Properties.cs index debff7e8596..4945e73d8e9 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.Properties.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.Properties.cs @@ -84,6 +84,8 @@ public bool IsOpen set { SetValue(IsOpenProperty, value); } } + internal BladeView ParentBladeView { get; set; } + private static void IsOpenChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { BladeItem bladeItem = (BladeItem)dependencyObject; diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs index 79373541841..4c38a417d7b 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs @@ -6,7 +6,9 @@ using Microsoft.Toolkit.Uwp.Extensions; using Windows.UI.Xaml; using Windows.UI.Xaml.Automation; +using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Controls; +using Microsoft.Toolkit.Uwp.UI.Automation.Peers; namespace Microsoft.Toolkit.Uwp.UI.Controls { @@ -92,6 +94,15 @@ protected override void OnCollapsed(EventArgs args) } } + /// + /// Creates AutomationPeer () + /// + /// An automation peer for this . + protected override AutomationPeer OnCreateAutomationPeer() + { + return new BladeItemAutomationPeer(this); + } + private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs) { if (IsExpanded) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs new file mode 100644 index 00000000000..2a8485fff3a --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs @@ -0,0 +1,84 @@ +// 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; +using Windows.UI.Xaml.Automation.Provider; + +namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers +{ + /// + /// Defines a framework element automation peer for the . + /// + public class BladeItemAutomationPeer : FrameworkElementAutomationPeer + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The that is associated with this . + /// + public BladeItemAutomationPeer(BladeItem owner) + : base(owner) + { + } + + private BladeItem OwnerBladeItem + { + get { return this.Owner as BladeItem; } + } + + /// + /// Gets the control type for the element that is associated with the UI Automation peer. + /// + /// The control type. + protected override AutomationControlType GetAutomationControlTypeCore() + { + return AutomationControlType.Custom; + } + + /// + /// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType, + /// differentiates the control represented by this AutomationPeer. + /// + /// The string that contains the name. + protected override string GetClassNameCore() + { + return Owner.GetType().Name; + } + + /// + /// Called by GetName. + /// + /// + /// Returns the first of these that is not null or empty: + /// - Value returned by the base implementation + /// - Name of the owning BladeItem + /// - Carousel class name + /// + 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; + } + + if (string.IsNullOrEmpty(name)) + { + name = this.GetClassName(); + } + + return $"{name} {index}"; + } + } +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs index bf0ff71639e..70b74cf8e1e 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs @@ -11,7 +11,9 @@ using Windows.Foundation.Collections; using Windows.UI.Core; using Windows.UI.Xaml; +using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Controls; +using Microsoft.Toolkit.Uwp.UI.Automation.Peers; namespace Microsoft.Toolkit.Uwp.UI.Controls { @@ -65,6 +67,7 @@ protected override void PrepareContainerForItemOverride(DependencyObject element if (blade != null) { blade.VisibilityChanged += BladeOnVisibilityChanged; + blade.ParentBladeView = this; } base.PrepareContainerForItemOverride(element, item); @@ -83,6 +86,15 @@ protected override void ClearContainerForItemOverride(DependencyObject element, base.ClearContainerForItemOverride(element, item); } + /// + /// Creates AutomationPeer () + /// + /// An automation peer for this . + protected override AutomationPeer OnCreateAutomationPeer() + { + return new BladeViewAutomationPeer(this); + } + private void CycleBlades() { ActiveBlades = new ObservableCollection(); @@ -200,5 +212,13 @@ private void ItemsVectorChanged(IObservableVector sender, IVectorChanged GetScrollViewer()?.ChangeView(_scrollViewer.ScrollableWidth, null, null); } } + + internal IEnumerable GetBladeItems() + { + return Enumerable + .Range(0, Items.Count) + .Select(idx => (BladeItem)ContainerFromIndex(idx)) + .Where(i => i != null); + } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs new file mode 100644 index 00000000000..15473efd253 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs @@ -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 +{ + /// + /// Defines a framework element automation peer for the control. + /// + public class BladeViewAutomationPeer : ItemsControlAutomationPeer + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The that is associated with this . + /// + public BladeViewAutomationPeer(BladeView owner) + : base(owner) + { + } + + private BladeView OwningBladeView + { + get + { + return Owner as BladeView; + } + } + + /// + /// Gets the control type for the element that is associated with the UI Automation peer. + /// + /// The control type. + protected override AutomationControlType GetAutomationControlTypeCore() + { + return AutomationControlType.Custom; + } + + /// + /// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType, + /// differentiates the control represented by this AutomationPeer. + /// + /// The string that contains the name. + protected override string GetClassNameCore() + { + return Owner.GetType().Name; + } + + /// + /// Called by GetName. + /// + /// + /// 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 + /// + protected override string GetNameCore() + { + string name = base.GetNameCore(); + if (!string.IsNullOrEmpty(name)) + { + return name; + } + + if (this.OwningBladeView != null) + { + name = this.OwningBladeView.Name; + } + + if (string.IsNullOrEmpty(name)) + { + name = this.GetClassName(); + } + + return name; + } + + /// + /// Gets the collection of elements that are represented in the UI Automation tree as immediate + /// child elements of the automation peer. + /// + /// The children elements. + protected override IList GetChildrenCore() + { + BladeView owner = OwningBladeView; + + ItemCollection items = owner.Items; + if (items.Count <= 0) + { + return null; + } + + List peers = new List(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; + } + } +} From b7988ae96cea8a8b796c8e8938803542f051ebc3 Mon Sep 17 00:00:00 2001 From: James Croft Date: Sat, 3 Oct 2020 15:38:24 +0100 Subject: [PATCH 2/5] Updated incorrect doc header for GetNameCore on BladeItemAutomationPeer --- .../BladeView/BladeItemAutomationPeer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs index 2a8485fff3a..78ce9b2975e 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs @@ -56,7 +56,7 @@ protected override string GetClassNameCore() /// Returns the first of these that is not null or empty: /// - Value returned by the base implementation /// - Name of the owning BladeItem - /// - Carousel class name + /// - BladeItem class name /// protected override string GetNameCore() { From ef2d15d53bbc51fab56f14134e495573ceecc6ef Mon Sep 17 00:00:00 2001 From: James Croft Date: Fri, 9 Oct 2020 20:00:40 +0100 Subject: [PATCH 3/5] Fixed using directives in BladeView automation changes --- Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs | 2 +- .../BladeView/BladeItemAutomationPeer.cs | 1 - Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs index 4c38a417d7b..21202d4d9fe 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.cs @@ -4,11 +4,11 @@ using System; using Microsoft.Toolkit.Uwp.Extensions; +using Microsoft.Toolkit.Uwp.UI.Automation.Peers; using Windows.UI.Xaml; using Windows.UI.Xaml.Automation; using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Controls; -using Microsoft.Toolkit.Uwp.UI.Automation.Peers; namespace Microsoft.Toolkit.Uwp.UI.Controls { diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs index 78ce9b2975e..f8cab223a4d 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs @@ -5,7 +5,6 @@ using System.Linq; using Microsoft.Toolkit.Uwp.UI.Controls; using Windows.UI.Xaml.Automation.Peers; -using Windows.UI.Xaml.Automation.Provider; namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers { diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs index 70b74cf8e1e..7119eadee61 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using Microsoft.Toolkit.Uwp.UI.Automation.Peers; using Microsoft.Toolkit.Uwp.UI.Extensions; using Windows.Foundation; using Windows.Foundation.Collections; @@ -13,7 +14,6 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Controls; -using Microsoft.Toolkit.Uwp.UI.Automation.Peers; namespace Microsoft.Toolkit.Uwp.UI.Controls { From e2d9e933bc4d074c5cf6f70bd563f80df0a38c0e Mon Sep 17 00:00:00 2001 From: James Croft Date: Sun, 22 Nov 2020 18:33:24 +0000 Subject: [PATCH 4/5] Updated BladeView and BladeItem --- .../BladeView/BladeItem.Properties.cs | 12 ++- .../BladeView/BladeItemAutomationPeer.cs | 94 +++++++++++++++++-- .../BladeView/BladeView.cs | 8 -- .../BladeView/BladeViewAutomationPeer.cs | 17 ++-- .../UI/Controls/Test_BladeView.cs | 36 +++++++ UnitTests/UnitTests.UWP/UnitTests.UWP.csproj | 1 + 6 files changed, 142 insertions(+), 26 deletions(-) create mode 100644 UnitTests/UnitTests.UWP/UI/Controls/Test_BladeView.cs diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.Properties.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.Properties.cs index 4945e73d8e9..72d44b730a5 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.Properties.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItem.Properties.cs @@ -39,6 +39,8 @@ public partial class BladeItem /// public static readonly DependencyProperty CloseButtonForegroundProperty = DependencyProperty.Register(nameof(CloseButtonForeground), typeof(Brush), typeof(BladeItem), new PropertyMetadata(new SolidColorBrush(Colors.Black))); + private WeakReference _parentBladeView; + /// /// Gets or sets the foreground color of the close button /// @@ -84,7 +86,15 @@ public bool IsOpen set { SetValue(IsOpenProperty, value); } } - internal BladeView ParentBladeView { get; set; } + internal BladeView ParentBladeView + { + get + { + this._parentBladeView.TryGetTarget(out var bladeView); + return bladeView; + } + set => this._parentBladeView = new WeakReference(value); + } private static void IsOpenChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs index f8cab223a4d..8aee497a2a2 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs @@ -2,9 +2,11 @@ // 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 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 { @@ -35,7 +37,7 @@ private BladeItem OwnerBladeItem /// The control type. protected override AutomationControlType GetAutomationControlTypeCore() { - return AutomationControlType.Custom; + return AutomationControlType.ListItem; } /// @@ -59,25 +61,97 @@ protected override string GetClassNameCore() /// protected override string GetNameCore() { - int? index = this.OwnerBladeItem.ParentBladeView.GetBladeItems().ToList().IndexOf(this.OwnerBladeItem); + string name = AutomationProperties.GetName(this.OwnerBladeItem); + if (!string.IsNullOrEmpty(name)) + { + return name; + } - string name = base.GetNameCore(); + name = this.OwnerBladeItem.Name; if (!string.IsNullOrEmpty(name)) { - return $"{name} {index}"; + return name; } - if (this.OwnerBladeItem != null && !string.IsNullOrEmpty(this.OwnerBladeItem.Name)) + TextBlock textBlock = this.OwnerBladeItem.FindDescendant(); + if (textBlock != null) { - return this.OwnerBladeItem.Name; + return textBlock.Text; } - if (string.IsNullOrEmpty(name)) + name = base.GetNameCore(); + if (!string.IsNullOrEmpty(name)) { - name = this.GetClassName(); + return name; } - return $"{name} {index}"; + return string.Empty; + } + + /// + /// Called by GetAutomationId that gets the **AutomationId** of the element that is associated with the automation peer. + /// + /// + /// The string that contains the automation ID. + /// + protected override string GetAutomationIdCore() + { + string automationId = base.GetAutomationIdCore(); + if (!string.IsNullOrEmpty(automationId)) + { + return automationId; + } + + if (this.OwnerBladeItem != null) + { + return this.GetNameCore(); + } + + return string.Empty; + } + + /// + /// Returns the size of the set where the element that is associated with the automation peer is located. + /// + /// + /// The size of the set. + /// + 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; + } + + /// + /// Returns the ordinal position in the set for the element that is associated with the automation peer. + /// + /// + /// The ordinal position in the set. + /// + 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; } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs index 7119eadee61..e2590010e48 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeView.cs @@ -212,13 +212,5 @@ private void ItemsVectorChanged(IObservableVector sender, IVectorChanged GetScrollViewer()?.ChangeView(_scrollViewer.ScrollableWidth, null, null); } } - - internal IEnumerable GetBladeItems() - { - return Enumerable - .Range(0, Items.Count) - .Select(idx => (BladeItem)ContainerFromIndex(idx)) - .Where(i => i != null); - } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs index 15473efd253..d2f8e6cadfa 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs @@ -4,6 +4,7 @@ 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; @@ -39,7 +40,7 @@ private BladeView OwningBladeView /// The control type. protected override AutomationControlType GetAutomationControlTypeCore() { - return AutomationControlType.Custom; + return AutomationControlType.List; } /// @@ -63,23 +64,25 @@ protected override string GetClassNameCore() /// protected override string GetNameCore() { - string name = base.GetNameCore(); + string name = AutomationProperties.GetName(this.OwningBladeView); if (!string.IsNullOrEmpty(name)) { return name; } - if (this.OwningBladeView != null) + name = this.OwningBladeView.Name; + if (!string.IsNullOrEmpty(name)) { - name = this.OwningBladeView.Name; + return name; } - if (string.IsNullOrEmpty(name)) + name = base.GetNameCore(); + if (!string.IsNullOrEmpty(name)) { - name = this.GetClassName(); + return name; } - return name; + return string.Empty; } /// diff --git a/UnitTests/UnitTests.UWP/UI/Controls/Test_BladeView.cs b/UnitTests/UnitTests.UWP/UI/Controls/Test_BladeView.cs new file mode 100644 index 00000000000..fa32042e85a --- /dev/null +++ b/UnitTests/UnitTests.UWP/UI/Controls/Test_BladeView.cs @@ -0,0 +1,36 @@ +// 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 Microsoft.Toolkit.Uwp.UI.Controls; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; +using Windows.UI.Xaml.Automation.Peers; +using Microsoft.Toolkit.Uwp.UI.Automation.Peers; + +namespace UnitTests.UWP.UI.Controls +{ + [TestClass] + [TestCategory("Test_BladeView")] + public class Test_BladeView + { + [UITestMethod] + public void ShouldConfigureBladeViewAutomationPeer() + { + const string automationName = "MyAutomationBlades"; + const string name = "MyBlades"; + + var bladeView = new BladeView(); + var bladeViewAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(bladeView) as BladeViewAutomationPeer; + + Assert.IsNotNull(bladeViewAutomationPeer, "Verify that the AutomationPeer is BladeViewAutomationPeer."); + + bladeView.Name = name; + Assert.IsTrue(bladeViewAutomationPeer.GetName().Contains(name), "Verify that the UIA name contains the given Name of the BladeView."); + + bladeView.SetValue(AutomationProperties.NameProperty, automationName); + Assert.IsTrue(bladeViewAutomationPeer.GetName().Contains(automationName), "Verify that the UIA name contains the given AutomationProperties.Name of the BladeView."); + } + } +} \ No newline at end of file diff --git a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj index a05bbb4e8e3..4f24302dafc 100644 --- a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj +++ b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj @@ -179,6 +179,7 @@ + From ad1800ad0de71edfebbd210a3d74d36ce9c6bc80 Mon Sep 17 00:00:00 2001 From: James Croft Date: Sat, 12 Dec 2020 12:24:49 +0000 Subject: [PATCH 5/5] Added change to include blade item header as potential GetNameCore result. --- .../BladeView/BladeItemAutomationPeer.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs index 8aee497a2a2..57033555a37 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs @@ -73,6 +73,12 @@ protected override string GetNameCore() return name; } + name = this.OwnerBladeItem.Header?.ToString(); + if (!string.IsNullOrEmpty(name)) + { + return name; + } + TextBlock textBlock = this.OwnerBladeItem.FindDescendant(); if (textBlock != null) {