AutomationProperties.LiveSetting no funciona en WPF en .NET Framework 4.7.1
Tengo un TextBlock y quiero rastrear ese control desde el lector de pantalla y cada vez que se establece un nuevo valor para el control en el código, el lector de pantalla debe leer el nuevo texto. Está disponible en WPF desde .NET Framework 4.7.1, que se menciona enMSDN LINK.
Pero siempre estoy recibiendonul Para el AutomationPeer valor. ¿Qué me falta en el código? ¿Lo estoy haciendo de la manera correcta? Por favor ayuda
XMAL
<Window x:Class="WPFAccessibility.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFAccessibility"
mc:Ignorable="d"
Title="WPFAccessibility" Height="450" Width="800">
<Grid>
<TextBlock Name="MyTextBlock" AutomationProperties.LiveSetting="Assertive">My initial text</TextBlock>
<Button Name="Save" Content="Save" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="50,321,0,0" Height="49" Click="Save_Click"/>
</Grid>
</Window>
Códig
private void Save_Click(object sender, RoutedEventArgs e)
{
// Setting the MyTextBlock text to some other value and screen
// reader should notify to the user
MyTextBlock.Text = "My changed text";
var peer = UIElementAutomationPeer.FromElement(MyTextBlock);
// I am always getting peer value null
peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
}