Skip to content

Commit

Permalink
Update AutomationPeer naming and types to be generalized (untested st…
Browse files Browse the repository at this point in the history
…ill with new base class)
  • Loading branch information
michael-hawker committed Mar 7, 2022
1 parent 968f1e6 commit 0ac40ef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// 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.Automation.Peers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Controls;

namespace Microsoft.Toolkit.Uwp.UI.Controls
Expand All @@ -14,13 +11,5 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
/// </summary>
public partial class ContentSizer : SizerBase
{
/// <summary>
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
/// </summary>
/// <returns>An automation peer for this <see cref="ContentSizer"/>.</returns>
protected override AutomationPeer OnCreateAutomationPeer()
{
return new ContentSizerAutomationPeer(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@

namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers
{
// TODO: Make this generalize for SizerBase?

/// <summary>
/// Defines a framework element automation peer for the <see cref="ContentSizer"/> control.
/// Defines a framework element automation peer for the <see cref="SizerBase"/> controls.
/// </summary>
public class ContentSizerAutomationPeer : FrameworkElementAutomationPeer
public class SizerAutomationPeer : FrameworkElementAutomationPeer
{
/// <summary>
/// Initializes a new instance of the <see cref="ContentSizerAutomationPeer"/> class.
/// Initializes a new instance of the <see cref="SizerAutomationPeer"/> class.
/// </summary>
/// <param name="owner">
/// The <see cref="ContentSizer" /> that is associated with this <see cref="T:Windows.UI.Xaml.Automation.Peers.ContentSizerAutomationPeer" />.
/// The <see cref="SizerBase" /> that is associated with this <see cref="SizerAutomationPeer" />.
/// </param>
public ContentSizerAutomationPeer(ContentSizer owner)
public SizerAutomationPeer(SizerBase owner)
: base(owner)
{
}

private ContentSizer OwningContentSizer
private SizerBase OwningSizer
{
get
{
return Owner as ContentSizer;
return Owner as SizerBase;
}
}

Expand All @@ -55,13 +53,13 @@ protected override string GetClassNameCore()
/// </returns>
protected override string GetNameCore()
{
string name = AutomationProperties.GetName(this.OwningContentSizer);
string name = AutomationProperties.GetName(this.OwningSizer);
if (!string.IsNullOrEmpty(name))
{
return name;
}

name = this.OwningContentSizer.Name;
name = this.OwningSizer.Name;
if (!string.IsNullOrEmpty(name))
{
return name;
Expand Down
13 changes: 11 additions & 2 deletions Microsoft.Toolkit.Uwp.UI.Controls.Layout/Sizers/SizerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +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 Windows.UI.Core;
using Microsoft.Toolkit.Uwp.UI.Automation.Peers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Markup;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
Expand Down Expand Up @@ -75,6 +75,15 @@ public SizerBase()
this.DefaultStyleKey = typeof(SizerBase);
}

/// <summary>
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
/// </summary>
/// <returns>An automation peer for this <see cref="SizerBase"/>.</returns>
protected override AutomationPeer OnCreateAutomationPeer()
{
return new SizerAutomationPeer(this);
}

/// <inheritdoc/>
protected override void OnApplyTemplate()
{
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/UnitTests.UWP/UI/Controls/Test_ContentSizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void ShouldConfigureContentSizerAutomationPeer()
const string name = "ContentSizer";

var contentSizer = new ContentSizer();
var contentSizerAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(contentSizer) as ContentSizerAutomationPeer;
var contentSizerAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(contentSizer) as SizerAutomationPeer;

Assert.IsNotNull(contentSizerAutomationPeer, "Verify that the AutomationPeer is ContentSizerAutomationPeer.");

Expand Down

0 comments on commit 0ac40ef

Please sign in to comment.