Repository: nvaccess/nvda

Issue:
NVDA is not announcing Item Status property changed events in WPF
### Steps to reproduce:
1. Download the [Visual Studio Community 2022](https://visualstudio.microsoft.com/vs/) installer.
1. Run the installer to install VS with the **Universal Windows Platform development** workload selected.
1. Open Visual Studio.
1. In the **Get started** dialog, click **Create a new project**.
1. In the search box, type "uwp" and select the first option **Blank App (Universal Windows)**.
1. Next -> Create -> OK.
1. Project -> Publish -> Create App Packages...
1. Next.
1. Select From Azure Key Vault...
1. Click on any of the WPF DataGrid column headers to change the sort direction of the column.

### Expected behavior:
Clicking on the column headers triggers a [AutomationPeer.RaisePropertyChangedEvent](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.automation.peers.automationpeer.raisepropertychangedevent?view=winrt-22621) to fire for the [AutomationElementIdentifiers.ItemStatusProperty](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.automation.automationelementidentifiers.itemstatusproperty?view=winrt-22621#windows-ui-xaml-automation-automationelementidentifiers-itemstatusproperty).

When using Narrator, this event will be announced in the form of a message that states the new item status. When the sort direction is ascending, it will announce "Column Name - Ascending". Likewise, when the sort direction is descending, it will announce "Column Name - Descending".

_The video below shows a user interacting with the "Select a certificate in Azure Key Vault" dialog in Visual Studio. In this dialog, there is a WPF DataGrid which is used to display information about code signing certificates that are stored in a Key Vault. The DataGrid contains 4 columns, each with a column header: Name, Status, Expiration Date, and Thumbprint. The user clicks on the Status column header and after Narrator finishes introducing some dialog context, it announces "Status Ascending". The user clicks on the Status column header again and Narrator announces "Status Descending" because the sort direction is now descending. Once more, the user clicks the column header to sort in ascending order and Narrator announced "Status Ascending". The user then performs these same steps on the Expiration Date column header where Narrator announced "Expiration Date Ascending" and "Expiration Date Descending" respectively._ 

https://user-images.githubusercontent.com/59936622/182099454-0d5982e1-0fd0-40fe-b511-78f87cde2ba8.mp4

### Actual behavior:
When using NVDA, there is only an announcement when the column header is hovered or first clicked, but none when the sort direction changes.

_The video below shows a user interacting with the "Select a certificate in Azure Key Vault" dialog in Visual Studio. In this dialog, there is a WPF DataGrid which is used to display information about code signing certificates that are stored in a Key Vault. The DataGrid contains 4 columns, each with a column header: Name, Status, Expiration Date, and Thumbprint. The user hovers over the Status column and NVDA announces "Status". The user clicks on the Status column header and after NVDA finishes introducing some dialog context, it announces "Status header item 2 of 4". The user clicks on the Status column header again to make the sort direction descending and NVDA makes no announcement. Once more, the user clicks the column header to sort in ascending order and NVDA makes no announcement. The user then performs these same steps on the Expiration Date column header where NVDA is once again not announcing the new Item Status of the column header._

https://user-images.githubusercontent.com/59936622/182313329-2a87d210-82f9-4f51-857f-28be8844a4a6.mp4

### NVDA logs, crash dumps and other attachments:
[nvda.log](https://github.com/nvaccess/nvda/files/9239933/nvda.log)

### System configuration
#### NVDA installed/portable/running from source:
Installed.

#### NVDA version:
2022.2

#### Windows version:
Edition	Windows 11 Pro
Version	21H2
Installed on	‎10/‎5/‎2021
OS build	22000.795
Serial number	MJ0EK6FF
Experience	Windows Feature Experience Pack 1000.22000.795.0

#### Name and version of other software in use when reproducing the issue:
Microsoft Visual Studio Enterprise 2022 (64-bit) - Preview
Version 17.3.0 Preview 5.0

#### Other information about your system:
N/A

### Other questions
#### Does the issue still occur after restarting your computer?
Yes.

#### Have you tried any other versions of NVDA? If so, please report their behaviors.
Have only tried latest version of NVDA.

#### If NVDA add-ons are disabled, is your problem still occurring?
No add-ons are installed.

#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Yes.


Discussion:
Hi, item status property event is defined in NVDA but there is no default implementation that works across apps (item status is retrieved as part of UIA object description getter in NVDA); this event was added specifically to support Action Center (quick settings in Windows 11) item changes. I have a feeling that this issue can be reproduced quite easily, and once I find it, I’ll publish a workaround in the form of an add-on. Thanks.


Maybe the reporter should consider adding your windows essentials add on to 
start with. NO idea if it will help in this case as its outside of my 
experience, but its a good start.
 Brian

-- 
***@***.***
Sent via blueyonder.(Virgin media)
Please address personal E-mail to:-
***@***.***, putting 'Brian Gaff'
in the display name field.
----- Original Message ----- 
From: "Joseph Lee" ***@***.***>
To: "nvaccess/nvda" ***@***.***>
Cc: "Subscribed" ***@***.***>
Sent: Tuesday, August 02, 2022 12:51 PM
Subject: Re: [nvaccess/nvda] NVDA is not announcing Item Status property 
changed events in WPF (Issue #13973)


Hi, item status property event is defined in NVDA but there is no default 
implementation that works across apps (item status is retrieved as part of 
UIA object description getter in NVDA); this event was added specifically to 
support Action Center (quick settings in Windows 11) item changes. I have a 
feeling that this issue can be reproduced quite easily, and once I find it, 
I’ll publish a workaround in the form of an add-on. Thanks.



-- 
Reply to this email directly or view it on GitHub:
https://github.com/nvaccess/nvda/issues/13973#issuecomment-1202383346
You are receiving this because you are subscribed to this thread.

Message ID: ***@***.***> 


Hi, it won’t help in this situation as I also need to confirm the report and think about how to support UIA item status property change event properly. What I wrote earlier still holds – there is no base implementation for handling item status events across aps – I contributed the needed changes to NVDA Core a few years ago specifically to deal with Windows 10 Action Center then. The solution is quite easy and difficult: easy because the base implementation can speak and braille item status property, difficult because one needs to hunt for a way to duplicate the issue described in a slightly easier way as not everyone uses Visual Studio (I can try duplicating it myself as I do have VS2022 on my system, but think about others who do not). Thanks.


Hi,

Update: what I suspected is happening.

Technical: as reported, UIA does fire item status property change event when the grid header changes. NVDA does include an example implementation of item status event handler for Windows 10 Action Center. The solution to this issue is to expand Action Center app module solution to UIA NVDA objects with one specific workaround: remove duplicate announcements via timestamp checks and/or caching. As promised, I will come up with a solution via Windows App Essentials NVDA add-on (as soon as within the next ten minutes, although the solution (for now) will result in duplicate item status announcements). Transforming the add-on solution into an actual NVDA screen reader pull request can take some time as we need to discuss design choices, but the idea is simple: add `event_UIA_itemStatus` event handler in `source/NVDAObjects/UIA/__init__.py` (if you are willing, I can walk you through this process provided that you would like to write the PR this week).

By the way, there is an add-on called Event Tracker that will log events as they occur, including (surprisingly enough) UIA item status property event.

Thanks.
Hi,

Here it is - linked is a try build of Windows App Essentials add-on that should resolve this issue. The official solution requires more thought since it must also resolve duplicate item status output:
https://github.com/josephsl/wintenApps/releases/download/22.08/wintenApps-try13973-20220802.nvda-addon

Thanks.

Resolving patch:
diff --git a/source/NVDAObjects/UIA/__init__.py b/source/NVDAObjects/UIA/__init__.py
--- a/source/NVDAObjects/UIA/__init__.py
+++ b/source/NVDAObjects/UIA/__init__.py
@@ -2035,6 +2035,19 @@ def event_UIA_notification(self, notificationKind=None, notificationProcessing=U
 				speech.cancelSpeech()
 			ui.message(displayString)
 
+	_itemStatusCache = None
+
+	def event_UIA_itemStatus(self):
+		"""
+		Base implementation of UIA item status property event.
+		By default NVDA will announce element name and item status if any.
+		"""
+		itemStatus = self.UIAElement.currentItemStatus
+		if itemStatus and itemStatus != self._itemStatusCache:
+			ui.message(f"{self.name} {itemStatus}")
+		self._itemStatusCache = itemStatus
+
+
 class TreeviewItem(UIA):
 
 	def _get_value(self):


Test patch: