Hi,@Ajay Gera. Welcome to Microsoft Q&A.
You could try the following method to let Narrator read the text content in Label.
You need to bind AutomationProperties.Name
to Label.Context
, and focus it manually (Label is not like button, which automatically focuses when clicked).
For the ToolTip in Label, it cannot be read by AutomationProperties.HelpText
like Button.
You could directly read the content of ToolTip through System.Speech.Synthesis
without going through Narrator.
System.Speech.Synthesis
requires the installation of the corresponding library. In the .Net environment, you could install System.Speech
through NuGet; in the .Net Framework environment, you could go to References->Right click->Add Reference...->Assemblies->Framework->Find System.Speech
and reference it.
<Grid>
<Label x:Name="MyLabel" HorizontalAlignment="Center" VerticalAlignment="Center" Content="This is a Label" AutomationProperties.Name="{Binding Path=Content,ElementName=MyLabel}"
Focusable="True" MouseEnter="MyLabel_MouseEnter" ToolTip="This is a ToolTip" ToolTipOpening="MyLabel_ToolTipOpening">
</Label>
</Grid>
using System.Speech.Synthesis;
private void MyLabel_MouseEnter(object sender, MouseEventArgs e)
{
MyLabel.Focus();
}
private void MyLabel_ToolTipOpening(object sender, ToolTipEventArgs e)
{
string text = MyLabel.ToolTip.ToString();
using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
{
synthesizer.Speak(text);
}
}
Run the WPF project and open Narrator by pressing Win+Ctrl+Enter
. When you move the mouse to the Label, you could hear the content of the Label.Content
. After a while, when the ToolTip is opening, you could hear the content of the ToolTip. I use ToolTipOpening
here. You could adjust the time according to your needs.
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.