Skip to content

[Windows] Implemented the AutomationPeers to the Border control #27713

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27627.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 27627, "[Windows] Border Automation Peer", PlatformAffected.UWP)]
public partial class Issue27627 : ContentPage
{
public Issue27627()
{
var grid = new Grid();

var border = new Border
{
AutomationId = "TestBorder",
VerticalOptions = LayoutOptions.Center,
HeightRequest = 100,
Stroke = Colors.Red
};

var label = new Label
{
Text = "Test Label",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};

border.Content = label;

grid.Children.Add(border);
Content = grid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue27627 : _IssuesUITest
{
public override string Issue => "[Windows] Border Automation Peer";

public Issue27627(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.Border)]
public void VerifyBorderAutomationPeer()
{
App.WaitForElement("TestBorder");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before you set the automation peer, is this not possible? I mean, this test appears to be looking for a element with this ID, so I just want to check if the test would fail without this new peer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the test failed without the new peer, and it passed after adding it. I have attached the output images for your reference.

Without this peer With this peer

}
}
}
11 changes: 11 additions & 0 deletions src/Core/src/Platform/Windows/ContentPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Hosting;
using Microsoft.UI.Xaml.Shapes;
using Microsoft.UI.Xaml.Automation.Peers;

namespace Microsoft.Maui.Platform
{
Expand Down Expand Up @@ -65,6 +66,16 @@ internal FrameworkElement? Content
return size;
}

protected override AutomationPeer OnCreateAutomationPeer()
{
if (CrossPlatformLayout is IBorderView)
{
return new MauiBorderAutomationPeer(this);
}

return base.OnCreateAutomationPeer();
}

public ContentPanel()
{
_borderPath = new Path();
Expand Down
25 changes: 25 additions & 0 deletions src/Core/src/Platform/Windows/MauiBorderAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls;

namespace Microsoft.Maui.Platform
{
// TODO: Make this class public in .NET 10.0. Issue Link: https://github.com/dotnet/maui/issues/30205
internal class MauiBorderAutomationPeer : FrameworkElementAutomationPeer
{
internal MauiBorderAutomationPeer(Panel owner) : base(owner) { }

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Pane;
}

protected override string GetClassNameCore()
{
return nameof(Panel);
}

protected override bool IsControlElementCore() => true;

protected override bool IsContentElementCore() => true;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Platform.ContentPanel.OnCreateAutomationPeer() -> Microsoft.UI.Xaml.Automation.Peers.AutomationPeer!