LabeledBy doesn't works in TextBlock | UWP

Anderson Rodrigues Cavalcante 271 Reputation points
2021-11-08T13:48:51.123+00:00

Hello,

I want to add accessibility to my UWP app. There is a TextBlock and a button. When focus is on the button, Narrator does not read the TextBlock, even using AutomationProperties.LabeledBy.

For example:

<TextBlock Text="Privacy Notice" AutomationProperties.LabeledBy="{Binding ElementName=btnPrivacyNotice}"/>
<Button Name="btnPrivacyNotice" Content="Agree"/>

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,856 Reputation points
    2021-11-09T02:51:49.487+00:00

    Hello,
    Welcome to Microsoft Q&A!

    LabeledBy doesn't works in TextBlock | UWP

    Please refer to Labels and LabeledBy document. The preferred way to associate a label with a form element is to use a TextBlock with an x:Name for label text, and then to set the AutomationProperties.LabeledBy attached property on the form element to reference the labeling TextBlock by its XAML name.

    So, you need to set AutomationProperties.LabeledBy for button but not for textblcok like the following

    <TextBlock x:Name="Privacy_Notice" Text="Privacy Notice" />  
    <Button Name="btnPrivacyNotice" Content="Agree"  AutomationProperties.LabeledBy="{Binding ElementName=Privacy_Notice}"/>  
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful