Announcing Control Changes for Screen Readers in My WPF Project?

fatih uyanık 200 Reputation points
2025-03-04T12:31:02.8766667+00:00

Hello everyone,

In my WPF project, I want to implement screen reader support, particularly in registration forms, for visually impaired users. My goal is to ensure that changes in controls (e.g., textboxes, comboboxes, checkboxes, etc.) and error messages are announced correctly by screen readers.

What adjustments can I make on the UI side to ensure that when any change occurs in the controls, it gets announced by the screen readers? Could you share any WPF features or methods that would help in achieving this functionality?

Thanks in advance.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,333 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hongrui Yu-MSFT 4,840 Reputation points Microsoft External Staff
    2025-03-05T03:26:15.0766667+00:00

    Hi, @fatih uyanık. Welcome to Microsoft Q&A. 

    You could set AutomationProperties.Name in controls (such as TextBox, RadioButton, CheckBox) to specify the words to be spoken. Refer to the following example:

    1.Editing Code

        <Grid x:Name="MyGrid" Width="200" Height="180" >
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Border BorderBrush="Black" BorderThickness="2" Padding="5" >
                <TextBox AutomationProperties.Name="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" ></TextBox>
            </Border>
            <Border BorderBrush="Black" BorderThickness="2" Padding="5" Grid.Row="1">
                <StackPanel>
                    <RadioButton GroupName="Sex" Content="A"  AutomationProperties.Name="You clicked radio button A"></RadioButton>
                    <RadioButton GroupName="Sex" Content="B"  AutomationProperties.Name="You clicked radio button B"></RadioButton>
                </StackPanel>
            </Border>
            <Border BorderBrush="Black" BorderThickness="2" Padding="5" Grid.Row="2">
                <StackPanel>
                    <CheckBox Content="C" Grid.Row="2" Grid.Column="1"  AutomationProperties.Name="You clicked CheckBox C"></CheckBox>
                    <CheckBox Content="D" Grid.Row="2" Grid.Column="1"  AutomationProperties.Name="You clicked CheckBox D"></CheckBox>
                    <CheckBox Content="E" Grid.Row="2" Grid.Column="1"  AutomationProperties.Name="You clicked CheckBox E"></CheckBox>
                </StackPanel>
            </Border>
        </Grid>
    

    2.Open Narrator on Windows: Ctrl+Win+Enter

    At this time, when you modify the content of the control, the corresponding words will be spoken.

    To read the error message, you coud refer to the following method:

    1.Editing Code

    <TextBlock x:Name="errorMessageTextBlock"  Width="0" Height="0"
       AutomationProperties.LiveSetting="Polite" 
       Visibility="Collapsed"/>
    
        public void ShowErrorMessage()
        {
            string message = "This is a Test";
    
            errorMessageTextBlock.Text = message;
            errorMessageTextBlock.Visibility = Visibility.Visible;
    
            // Create an automation peer for the TextBlock
            var peer = UIElementAutomationPeer.CreatePeerForElement(errorMessageTextBlock);
            if (peer != null)
            {
                // Raise the LiveRegionChanged event
                peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
            }
        }
    

    2.Open Narrator on Windows: Ctrl+Win+Enter

    Now when you run ShowErrorMessage(), you will hear the error message.


    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.