dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.29k stars 956 forks source link

WinForms TabControl does not expose TabItem controls to UIAutomation #10408

Open leind375 opened 7 months ago

leind375 commented 7 months ago

.NET version

.NET 8

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes, I believe it was working in .NET 6.

Issue description

For a WinForms TabControl, the tab page is exposed through UIAutomation but the TabItem controls are missing so there is no way for automations to switch between tabs.

Steps to reproduce

Create a WinForms app. Add a TabControl. By default it will have to pages. Run it. Walk the tree of the application. Tab page is there but no TabItem controls.

Tanya-Solyanik commented 7 months ago

@Olina-Zhang - Could you please verify when this scenario regressed? Consider using https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/navigate-among-ui-automation-elements-with-treewalker to build a sample

Olina-Zhang commented 7 months ago

@Tanya-Solyanik I cannot create a sample followed that document provided successfully. And test tabControls in Inspect by Navigation, it has same results in .Net 8.0 and .Net 6.0, TabItems under TabControl are in UIA tree and focused. @leind375 Could you please add more information to demonstrate your issue?

https://github.com/dotnet/winforms/assets/26474449/0f564d0b-41a9-471b-b2c6-690449a861d3

LeafShi1 commented 7 months ago

@Olina-Zhang - Could you please verify when this scenario regressed? Consider using https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/navigate-among-ui-automation-elements-with-treewalker to build a sample

I tried to write an sample using Example 2, in the .netFramwork 4.8.1 project, TreeWalker can obtain the tabitem, image

but In the .netcore project, TreeWalker obtain the panel. image

Sample(the 'UIAutomationClient.dll' and 'UIAutomationTypes.dll' need to be referenced, I am referencing the dlls from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8.1): WindowsFormsApp3.zip

Olina-Zhang commented 7 months ago

Thanks @LeafShi1. Verified it is regressed from .Net 6.0, cannot repro in .Net Core 3.1 and .Net 5.0.

.Net 6.0 behavior: image

.Net 5.0: image

SimonZhao888 commented 6 months ago

When we use reverse lookup, TreeWalker can obtain the TabItem controls. image image WinFormsApp71.zip

@leind375, hope this can help you to solve your problem.

ghost commented 6 months ago

This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.

It will be closed if no further activity occurs within 7 days of this comment.

leind375 commented 6 months ago

Adding a comment to keep the defect open. The workaround will help us short term but would still like to see this fixed so we can avoid all the overrides we'll need to implement on future UI.

leind375 commented 4 months ago

The workaround above (using GetLastChild() and GetPreviousSibling() also has a defect - GetPreviousSibling is also returning children, not just siblings.

SimonZhao888 commented 4 months ago

The workaround above (using GetLastChild() and GetPreviousSibling() also has a defect - GetPreviousSibling is also returning children, not just siblings.

We need to modify the code appropriately, e.g. try to use TreeWalker(Condition condition), here is the example code: 1

@leind375, Will this meet your requirements?

leind375 commented 4 weeks ago

@SimonZhao888 Yes, I can work with this for now. Would still like to see this fixed. Starting to add a lot of hacks in UIA code...