MahApps / MahApps.Metro

A framework that allows developers to cobble together a better UI for their own WPF applications with minimal effort.
https://mahapps.com
MIT License
9.23k stars 2.45k forks source link

Unable to use Automation Peer on controls using Mahapps framework #4454

Open alexandrefaure opened 7 months ago

alexandrefaure commented 7 months ago

Hi everyone,

We currently have a bug on our application which seems to be directly related to the .Net 8.0 upgrade. We need to access to AutomationPeers of controls inside our app for our quality team. From the dev side, we use Accessibility Insight to verify that each control in the app have a correct/dedicated AutomationId.

Since we've upgraded to .Net 8.0 last week, we cannot find our controls anymore using Mahapps. When we remove Mahapps lib from our code, everything went fine and we can find our controls.

I can give you a test project with a simple button to test that if necessary. Of course, we use the latest version of Mahapps.

Feel free to tell me if you need more information.

Thanks again for your help, Cheers, Alex

punker76 commented 7 months ago

@alexandrefaure Sorry to here this, a sample would be helpful. Do you use still 2.4.10?

alexandrefaure commented 7 months ago

Yep for sure we use the version 2.4.10.

Here is a .zip with the light solution with a button in center of a window. How I made the test :

  1. Run the app without debugging
  2. Launch Accessibility Insight
  3. We can target the control (using AutomationPeers) correctly as shown here : image

When it's not working, we cannot targeting the control anymore : image

Here are the different test cases :

  1. With Mahapps lib + .Net 7.0 set as project target version = OK
  2. With Mahapps lib + .Net 8.0 set as project target version = KO
  3. Without Mahapps lib + .Net 8.0 set as project target version = OK

Here is the .zip file with the solution used for this test.

Hope that helps ! App 8.zip

noubar commented 5 months ago

I can only reassure that the bug is there, because i was having the same problem not only with windows accessibility insights but with inspect.exe from microsoft and UIRecorder from WinAppDriver and FlaUInspect.

Bug reproduction steps are:

  1. Download the zip file
  2. make sure you are using latest metroapp version and .net8
  3. Change the Window under MainWindow.xml to mah:MetroWindow
  4. Build the app
  5. Start the app without debugging
  6. Try to inspect the button with any inspection tool

Expected result:

Actual result:

Extra info:

These all inspect tools are using the frompoint function from windows https://learn.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement.frompoint?view=windowsdesktop-8.0

textdocument commented 1 month ago

I can also confirm that the bug is there.

noubar commented 1 day ago

I have a workaround for this issue, which is not a fix but a total workaround. An updated version of flauinspect. Which uses focused element instead of mouse position to detect the element. I have an implementation of it here in an inspector app. Use uia2 and activate focus mode. with holding the right alt click on the searched element. This way it works.

lightwalker01 commented 1 day ago

@noubar thanks for your comment: unfortunately we cannot apply your workaround so this issue with .Net 8.0, still open after 7 months, is really a problem for us...

Maybe it is related to https://github.com/dotnet/wpf/issues/8679?

noubar commented 1 day ago

It looks like that it is related. But not 100% the same thing because the error described in there that the element tree is missing some elements i have not observed such an error in the metro window.