-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Windows] Border: Add automation peer and keyboard tap support #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
base: main
Are you sure you want to change the base?
Changes from all commits
603f903
0c48bb2
4a5ecb9
3291b82
107be52
c3156e1
b86bb18
4346ac4
f370bb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 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, | ||
| Padding = new Thickness(10), | ||
| Stroke = Colors.Red | ||
| }; | ||
|
|
||
| var label = new Label | ||
| { | ||
| Text = "Welcome to Maui!", | ||
| AutomationId = "TestLabel", | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| VerticalOptions = LayoutOptions.Center | ||
| }; | ||
|
|
||
| var nestedBorder = new Border | ||
| { | ||
| Stroke = Colors.Blue, | ||
| AutomationId = "NestedBorder", | ||
| StrokeThickness = 2, | ||
| Padding = new Thickness(10), | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| VerticalOptions = LayoutOptions.Center, | ||
| }; | ||
|
|
||
| nestedBorder.Content = label; | ||
| border.Content = nestedBorder; | ||
|
|
||
| grid.Children.Add(border); | ||
| Content = grid; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| 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() | ||
| { | ||
| // Check whether the parent Border is found or not | ||
| App.WaitForElement("TestBorder"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // Check whether the nested Border is found or not | ||
| App.WaitForElement("NestedBorder"); | ||
|
|
||
| // Check whether the Label inside the nested Border is found or not | ||
| App.WaitForElement("TestLabel"); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using Microsoft.UI.Xaml.Automation; | ||
| using Microsoft.UI.Xaml.Automation.Peers; | ||
| using Microsoft.UI.Xaml.Controls; | ||
|
|
||
| namespace Microsoft.Maui.Platform | ||
| { | ||
| // TODO: Make this class public in .NET11.0. Issue Link: https://github.com/dotnet/maui/issues/30205 | ||
| internal partial class MauiBorderAutomationPeer : FrameworkElementAutomationPeer | ||
| { | ||
| internal MauiBorderAutomationPeer(Panel owner) : base(owner) { } | ||
|
|
||
| // Control Type: Returns "Pane" as the control type for the border automation peer | ||
| protected override AutomationControlType GetAutomationControlTypeCore() | ||
| { | ||
| return AutomationControlType.Pane; | ||
| } | ||
|
|
||
| // Class Name: Returns "Panel" as the class name for the border automation peer | ||
| protected override string GetClassNameCore() | ||
| { | ||
| return nameof(Panel); | ||
| } | ||
|
|
||
| // Keyboard Focusable: Allows border to receive keyboard focus only when it has gesture recognizers (IsTabStop = true) | ||
| protected override bool IsKeyboardFocusableCore() => (Owner as ContentPanel)?.IsTabStop == true; | ||
|
|
||
| // Control View: Expose only when the Border is interactive (has tap gestures) or has an explicit AutomationId | ||
| protected override bool IsControlElementCore() => IsInteractiveOrNamed(); | ||
|
|
||
| // Content View: Expose only when the Border is interactive (has tap gestures) or has an explicit AutomationId | ||
| protected override bool IsContentElementCore() => IsInteractiveOrNamed(); | ||
|
|
||
| // Gates automation exposure: Border appears in the control/content view only when it is interactive | ||
| // (IsTabStop == true, set by GesturePlatformManager when tap gestures are present) or explicitly | ||
| // named via AutomationId (opted-in for automation visibility by the developer). | ||
| bool IsInteractiveOrNamed() | ||
| { | ||
| if (Owner is not ContentPanel contentPanel) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return contentPanel.IsTabStop || !string.IsNullOrEmpty(AutomationProperties.GetAutomationId(contentPanel)); | ||
| } | ||
| } | ||
| } |
| 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! |


Uh oh!
There was an error while loading. Please reload this page.