microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Narrator repeats one extra time at ToggleSwitch when OnContent or OffContent is set in UWP

Open riqmariz opened this issue 1 year ago • 0 comments

Describe the bug

I am currently implementing a custom ToggleSwitch in UWP based on Microsoft's template. However, I've encountered a peculiar bug related to the narrator behavior, which seems to be resolved in WinUI 3 but persists in UWP (WinUI 2). I'm seeking assistance to address this issue.

If the OnContent or OffContent is set at the toggle switch it will cause the narrator to repeat itself one time. If you don't use this properties, it reads perfectly, without repeating itself.

<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
        <ToggleSwitch x:Name="A" />
        <Grid>
            <ToggleSwitch
                x:Name="B"
                OffContent="Disable"
                OnContent="Enable"
               />
        </Grid>
    </StackPanel>

In the provided example code, the first ToggleSwitch with the x:Name 'A' behaves correctly. However, when the OnContent and OffContent properties are set, as in the second ToggleSwitch with the x:Name 'B,' the narrator repeats itself one extra time. The expected behavior is to read 'Enable, Toggle Switch, ON' or 'Disable, Toggle Switch, OFF,' but it reads something like 'Enable, Toggle Switch, ON, Enable, Toggle Switch, ON." or the analogue

How can I overcome this issue and prevent the narrator from repeating itself when using the OnContent and OffContent properties in a UWP ToggleSwitch? Any insights or workarounds would be greatly appreciated.

Steps to reproduce the bug

  1. Go to your UWP project with the code snippet described;
  2. Select Toggle Switch component that has OnContent and OffContent;
  3. Have narrator activated;
  4. Navigate through the keyboard to component (Or Click);
  5. Press space key to change value; [BUG] - Narrator read twice: On/Off Content+ component+ state

Expected behavior

Narrator read once: On/Off Content+ component+ state

Screenshots

image

Toggle Switch Narrator Test.zip

NuGet package version

WinUI 2 - Microsoft.UI.Xaml 2.8.2

Windows version

Windows 10: Build 19041 (version 2004)

Additional context

I've already posted something similar at: https://learn.microsoft.com/en-us/answers/questions/1526247/how-to-make-narrator-do-not-repeat-the-sentence-wh

I still had no success to work this around.

I've attempted to use AutomationProperties.SetName(component, name) but it does not work in every scenario for me.

Also, tried to implement a AutomationPeer but the ToggleSwitch is a sealed class. Therefore, I'm using composition. As a result, I couldn't use ToggleSwitchAutomationPeer even when passing the component as a parameter. I attempted to use FrameworkElementAutomationPeer instead and I've implemented it similarly to ToggleSwitchAutomationPeer (like described on the section remarks on this link ToggleSwitchAutomationPeer) but it always seems to result in a wrong case, not always on the narrator, but sometimes it don't focus right with the proper narrator border, because the control itself do not inherits from toggle switch, it contains one toggle switch, that messes everything up.

riqmariz avatar Feb 09 '24 15:02 riqmariz