Vic*_*ica 9 c# wpf accessibility
我完全失明了,我使用 NVDA 屏幕阅读器来操作系统,并且我正在尝试创建一个 Windows 桌面应用程序。Visual Studio 对屏幕阅读器不友好,至少对表单设计器部分不友好。VS Code 非常容易访问,尽管 powershell 的 protools 设计器却不然。
每当我看到关于用纯代码在 WPF 中编写 GUI 的问题时,我都会发现很多“看在上帝的份上你为什么要这样做?使用 VS!” 答案。好吧,原因是,VS 表单设计器对于盲人程序员来说是遥不可及的,所以必须采用最不实用的方法。
那么,可以吗?您会建议任何资源或方法吗?
我将尝试从其他示例开始构建,以获得可编译的代码。要使 WPF 正常工作,您需要一个使用 WPF 支持构建的项目。
最简单的方法是自己创建一个.csproj并使用之前发布的纯代码解决方案。
因此,从一个最小的文件开始,App.csproj如下所示:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>
</Project>
然后像以前一样输入应用程序和窗口代码App.cs。我向其中添加了几个控件,因为StackPanel如果您想稍后开始添加更多内容,您无论如何都需要一个容器(我使用过)。
using System;
using System.Windows;
using System.Windows.Controls;
public class App : Application {
    protected override void OnStartup(StartupEventArgs e)     {
        base.OnStartup(e);
        new MainWindow().Show();
    }
    [STAThread]
    public static void Main() => new App().Run();
}
public class MainWindow : Window {
    protected override void OnInitialized(EventArgs e) {
        base.OnInitialized(e);
        var panel = new StackPanel();
        this.Content = panel;
        var label = new Label { Content = "Click me:" };
        panel.Children.Add(label);
        
        var closeButton = new Button { Content = "Close", Height = 100 };
        closeButton.Click += (sender, args) => this.Close();
        panel.Children.Add(closeButton);
        (this.Width, this.Height) = (200, 200);
    }
}
然后,您可以使用 来构建整个项目dotnet build。您可以使用dotnet run或直接调用 exe 来运行它。
或者,如果您想探索具有单独的 .xaml 和 .xaml.cs 代码的 WPF 项目,您可以使用dotnet new wpf -o MyProjectName. 这将生成一个项目、一个基于 xaml 的应用程序和一个基于 xaml 的表单。