microsoft / microsoft/microsoft-ui-xaml

IUIAutomationPropertyChangedEventHandler events not fired when attached to a winui3 window

Open
#10,645 1 comment 0 reactions 0 assignees View on GitHub
bug needs-triage
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

We want to add UI automation to test our app. I found out after implementing `IUIAutomationPropertyChangedEventHandler` I did not see any events fired either attaching to root window / sink window.

### Steps to reproduce the bug

1. Create a console application that prints out the event, implement `IUIAutomationPropertyChangedEventHandler` like this. This is basically coped from the [official doc](https://learn.microsoft.com/en-us/windows/win32/winauto/uiauto-howto-implement-event-handlers#handling-property-changed-events)
```cpp
class EventHandler :
public IUIAutomationPropertyChangedEventHandler
{
private:
LONG _refCount;

public:
int _eventCount;

//Constructor.
EventHandler() : _refCount(1), _eventCount(0)
{
}

//IUnknown methods.
ULONG STDMETHODCALLTYPE AddRef()
{
ULONG ret = InterlockedIncrement(&_refCount);
return ret;
}

ULONG STDMETHODCALLTYPE Release()
{
ULONG ret = InterlockedDecrement(&_refCount);
if (ret == 0)
{
delete this;
return 0;
}
return ret;
}

HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppInterface)
{
if (riid == __uuidof(IUnknown))
*ppInterface = static_cast(this);
else if (riid == __uuidof(IUIAutomationPropertyChangedEventHandler))
*ppInterface = static_cast(this);
else
{
*ppInterface = NULL;
return E_NOINTERFACE;
}
this->AddRef();
return S_OK;
}

// IUIAutomationPropertyChangedEventHandler methods.
HRESULT STDMETHODCALLTYPE HandlePropertyChangedEvent(IUIAutomationElement* pSender, PROPERTYID propertyID, VARIANT newValue)
{
_eventCount++;
printf("Property: %s changed, count: %d\n", AutomationPropertyIdToString(propertyID), _eventCount);
return S_OK;
}
};

```

Then attach the event handler like this
```cpp
PROPERTYID pPIDProperties[] = { UIA_NamePropertyId, UIA_FrameworkIdPropertyId, UIA_AutomationIdPropertyId };
pAutomation->AddPropertyChangedEventHandlerNativeArray(pTargetElement, TreeScope_Subtree, NULL, (IUIAutomationPropertyChangedEventHandler*)pEHTemp, pPIDProperties, sizeof(pPIDProperties) / sizeof(pPIDProperties[0]));
```

2. Create a new winui3 project, add a button that changes its content when clicked
3. Run the winui3 project, and the automation project, click on the button, no console output is printed.

### Expected behavior

At least the name property changed should got printed, because I use `inspect.exe` tools to check, the button text are reflected as its name property.

### Screenshots

_No response_

### NuGet package version

WinUI 3 - Windows App SDK 1.7.3: 1.7.250606001

### Windows version

Windows 11 (24H2): Build 26100

### Additional context

[See here for full repro project](https://github.com/HO-COOH/WinUI-Bug/tree/main/30-AutomationEventNotFired)

Contributor guide

Open the contributing guide

Research direction

Start with the linked WinUI-Bug/30-AutomationEventNotFired repro and run the console automation app alongside the WinUI 3 app. Verify whether IUIAutomationPropertyChangedEventHandler receives events for the button's changing content; done means the expected property-change event is delivered and printed.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
accessibility, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.