Search code examples
c#buttonuwp

Set automation property of a button in CS file


I have a UWP app which has a button implemented in .cs file. Button was created using this code in CS file,

var button = new Button();
button.Background = new SolidColorBrush();
button.Opacity = 1.0;
button.Name = "Test Button";

But when I tried Narrator it does not Say the complete button name. Just say, "Button". Is there any way to change the name properties some way so that Narrator tells it properly?

I have tried "button.Name" and "button.Content" but both does not work. And Narrator does not say complete name of the button.


Solution

  • This is a summary based on @MySpaceDotNet's comment.

    Please set the AutomationProperties.Name property of the control for accessibility purposes. This property is designed for screen readers like Narrator.

    You could add the following code:

    AutomationProperties.SetName(button, "Test Button");