1

I want to create an accessible application. I want to show pdf files in TextBlock page by page but when I change the CurrentPage properties on EbookViewerViewModel the NVDA Screen Reader doesn't read It the text again. I thought if I set focus again the Screen Reader will read it, but doesn't. Can I solve this problem somehow?

The EbookViewerWindow.xaml contains this:

<Window x:Class="myproj.EbookViewerWindow"
    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:myproj"
    mc:Ignorable="d"
    Title="AEBCA - Könyv megjelenítő" Height="300" Width="300" Closed="Window_Closed" WindowStartupLocation="CenterScreen" KeyDown="Window_KeyDown">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="40"></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <TextBlock Grid.Row="0" Grid.Column="0" x:Name="AuthorTB" Text="{Binding Author}" AutomationProperties.Name="A könyv szerzője" AutomationProperties.HelpText="{Binding Author}" Focusable="True"></TextBlock>
    <TextBlock Grid.Row="0" Grid.Column="1" x:Name="BookNameTB" Text="{Binding BookName}" AutomationProperties.Name="A könyv címe" AutomationProperties.HelpText="{Binding BookName}" Focusable="True"></TextBlock>
    <DockPanel Grid.Row="1" Grid.ColumnSpan="2">
        <TextBlock x:Name="CurrentPageTB" Text="{Binding CurrentPage}" AutomationProperties.Name="A könyv tartalma" AutomationProperties.HelpText="{Binding CurrentPage}" Focusable="True"></TextBlock>
        <Label x:Name="help"></Label>
    </DockPanel>
</Grid>

In the code behind I do this:

public partial class EbookViewerWindow : Window
{
    EbookViewerViewModel vm;
    int index = 0;
    PdfReader pdfReader;
    public EbookViewerWindow()
    {
        InitializeComponent();
        vm = new EbookViewerViewModel();
        DataContext = vm;
        vm.Author = "Antoine de Saint-Exupéry";
        vm.BookName = "A Kis Herceg";
        AuthorTB.Focus();

        string fileName = @"d:\pdf.pdf";
        if (File.Exists(fileName))
        {
            pdfReader = new PdfReader(fileName);
            NextPage(pdfReader);
        }
    }

    private void Window_Closed(object sender, EventArgs e)
    {
        MainWindow mainWindow = new MainWindow();
        mainWindow.Show();
    }

    private void Window_KeyDown(object sender, KeyEventArgs e)
    {
        if(e.Key == Key.Right)
        {
            NextPage(pdfReader);
            CurrentPageTB.Focus();
            e.Handled = true;
        }
        if(e.Key == Key.Left)
        {
            PreviousPage(pdfReader);
            CurrentPageTB.Focus();
            e.Handled = true;
        }
    }

    private void NextPage(PdfReader pdfReader)
    {
        index++;
        int pages = pdfReader.NumberOfPages;
        ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
        string currentText = index.ToString() + ". oldal \n";
        string temp = PdfTextExtractor.GetTextFromPage(pdfReader, index, strategy);
        currentText += temp;
        vm.CurrentPage = currentText;
    }

    private void PerviousPage(PdfReader pdfReader)
    {
        index--;
        int pages = pdfReader.NumberOfPages;
        ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
        string currentText = index.ToString() + ". oldal \n";
        string temp = PdfTextExtractor.GetTextFromPage(pdfReader, index, strategy);
        currentText += temp;
        vm.CurrentPage = currentText;
    }
}
}

My EbookViewerViewModel:

public class EbookViewerViewModel : BaseViewModel
{
    private string currentPage;
    public string BookName { get; set; }
    public string Author { get; set; }
    public string CurrentPage { get { return currentPage; } set { currentPage = value; OnPropertyChanged(); } }
}
Tamás Deák
  • 175
  • 1
  • 13

1 Answers1

1

I found answer here:

How do I make screen readers read my WPF message similarly to how they read Win32 MessageBox?

<DockPanel Grid.Row="1" Grid.ColumnSpan="2">
        <TextBlock x:Name="CurrentPageTB" Text="{Binding CurrentPage}" Focusable="True">
            <Run AutomationProperties.Name="A könyv tartalma" AutomationProperties.HelpText="{Binding CurrentPage}"></Run>
        </TextBlock>
</DockPanel>
Tamás Deák
  • 175
  • 1
  • 13