【.NET Framework & C#】What's new in accessibility in the .NET Framework
What's new in accessibility in the .NET Framework
The .NET Framework aims(vt. 目的在于;引导;把…对准) at making applications more accessible for your users. Accessibility features allow an application to provide an appropriate experience for users of Assistive Technology. Starting with the .NET Framework 4.7.1, the .NET Framework includes a large number of accessibility improvements that allow developers to create accessible applications.
Accessibility switches
You can configure your app to opt into accessibility features if it targets the .NET Framework 4.7 or an earlier version but is running on the .NET Framework 4.7.1 or later. You can also configure your app to use legacy(n. 遗赠,遗产) features (and not take advantage of accessibility features) if it targets the .NET Framework 4.7.1 or later. Each version of the .NET Framework that includes accessibility features has a version-specific accessibility switch, which you add to the <AppContextSwitchOverrides>
element in the <runtime>
section of the application's configuration file. The following are the supported switches:
Version | Switch |
---|---|
.NET Framework 4.7.1 | "Switch.UseLegacyAccessibilityFeatures" |
.NET Framework 4.7.2 | "Switch.UseLegacyAccessibilityFeatures.2" |
Taking advantage of accessibility enhancements
The new accessibility features are enabled by default for applications that target the .NET Framework 4.7.1 or later. In addition, applications that target an earlier version of the .NET Framework but are running on the .NET Framework 4.7.1 or later can opt out of legacy accessibility behaviors (and thereby(adv. 从而,因此;在那附近;在那方面) take advantage of accessibility improvements) by adding switches to the <AppContextSwitchOverrides>
element in the <runtime>
section of the application's configuration file and setting their value to false
. The following shows how to opt in to accessibility enhancements introduced in the .NET Framework 4.7.1:
<runtime> <!-- AppContextSwitchOverrides value attribute is in the form of 'key1=true|false;key2=true|false --> <AppContextSwitchOverrides value="Switch.UseLegacyAccessibilityFeatures=false" /> </runtime>
If you choose to opt in to accessibility features in a later version of the .NET Framework, you must also explicitly opt in to the features from earlier versions of the .NET Framework. Configuring your app to take advantage of accessibility improvements in both the .NET Framework 4.7.1 and 4.7.2 requires the following <AppContextSwitchOverrides>
element:
<runtime> <!-- AppContextSwitchOverrides value attribute is in the form of 'key1=true|false;key2=true|false --> <AppContextSwitchOverrides value="Switch.UseLegacyAccessibilityFeatures=false;Switch.UseLegacyAccessibilityFeatures.2=false" /> </runtime>
Restoring legacy behavior
Applications that target versions of the .NET Framework starting with 4.7.1 can disable accessibility features by adding switches to the <AppContextSwitchOverrides>
element in the <runtime>
section of the application's configuration file and setting their value to true
. For example, the following configuration opts out of accessibility features introduced in .NET Framework 4.7.2:
<runtime> <!-- AppContextSwitchOverrides value attribute is in the form of 'key1=true|false;key2=true|false --> <AppContextSwitchOverrides value="Switch.UseLegacyAccessibilityFeatures.2=true" /> </runtime>
What's new in accessibility in the .NET Framework 4.7.2
The .NET Framework 4.7.2 includes new accessibility features in the following areas:
Windows Forms
OS-defined colors in High Contrast(vi. 对比;形成对照) themes
Starting with .NET Framework 4.7.2, Windows Forms uses colors defined by the operating system in High Contrast themes. This affects the following controls:
-
The drop-down arrow of the ToolStripDropDownButton control.
-
The Button, RadioButton and CheckBox controls with FlatStyle set to FlatStyle.Flat or FlatStyle.Popup. Previously, selected text and background colors were not contrasting and were hard to read.
-
Controls contained within a GroupBox that has its Enabled property set to
false
. -
The ToolStripButton, ToolStripComboBox, and ToolStripDropDownButton controls, which have an increased luminosity(n. [光][天] 光度;光明;光辉) contrast ratio in High Contrast Mode.
-
The LinkColor property of the DataGridViewLinkCell.
Narrator(n. 叙述者;解说员) improvements
Starting with the .NET Framework 4.7.2, Narrator support is enhanced as follows:
-
It announces the value of the ToolStripMenuItem.ShortcutKeys property when announcing the text of a ToolStripMenuItem.
-
It indicates when a ToolStripMenuItem has its Enabled property set to
false
. -
It gives feedback on the state of a check box when the ListView.CheckBoxes property is set to
true
. -
Narrator's Scan Mode focus order is consistent with the visual order of the controls on the ClickOnce download dialog window.
DataGridView improvements
Starting with the .NET Framework 4.7.2, the DataGridView control has introduced the following accessibility improvements:
-
Rows can be sorted using the keyboard. A user can use the F3 key in order to sort by the current column.
-
When the DataGridView.SelectionMode is set to DataGridViewSelectionMode.FullRowSelect, the column header changes color to indicate the current column as the user tabs through the cells in the current row.
-
The AccessibleObject.Parent property of aSystem.Windows.Forms.DataGridViewLinkCell.DataGridViewLinkCellAccessibleObject returns the correct parent control.
Improved visual cues
- The RadioButton and CheckBox controls with an empty Text property display a focus indicator when they receive the focus.
Improved Property Grid Support
-
The PropertyGrid control child elements now return a
true
for the IsReadOnlyProperty property only when a PropertyGrid element is enabled. -
The PropertyGrid control child elements return a
false
for the IsEnabledProperty property only when a PropertyGrid element can be changed by the user.
Improved keyboard navigation
- The ToolStripButton control allows focus when contained within a ToolStripPanel that has the TabStop property set to
true
Windows Presentation Foundation (WPF)
Changes to the CheckBox and RadioButton controls
In the .NET Framework 4.7.1 and earlier versions, the WPF CheckBox and RadioButton controls have inconsistent and, in Classic and High Contrast themes, incorrect focus visuals(adj. 视觉的,视力的;栩栩如生的). These issues occur in cases where the controls do not have any content set. This can make the transition(n. 过渡;转变;[分子生物] 转换;变调) between themes confusing and the focus visual hard to see.
In the .NET Framework 4.7.2, these visuals are now more consistent across themes and more easily visible in Classic and High Contrast themes.
WinForms controls hosted in a WPF application
For WinForms control hosted in a WPF application in the .NET Framework 4.7.1 and earlier versions, users couldn't tab out of the WinForms layer if the first or last control in that layer is the WPF ElementHost control. In the .NET Framework 4.7.2, users are now able to tab out of the WinForms layer.
However, automated applications that rely on focus never escaping the WinForms layer may no longer work as expected.
What's new in accessibility in the .NET Framework 4.7.1
The .NET Framework 4.7.1 includes new accessibility features in the following areas:
Windows Presentation Foundation (WPF)
Screen reader improvements
If accessibility improvements are enabled, the .NET Framework 4.7.1 includes the following enhancements that affect screen readers:
-
In the .NET Framework 4.7 and earlier versions, Expander controls were announced by screen readers as buttons. Starting with the .NET Framework 4.7.1, they are correctly announced as expandable/collapsible groups.
-
In the .NET Framework 4.7 and earlier versions, DataGridCell controls were announced by screen readers as “custom.” Starting with the .NET Framework 4.7.1, they are now correctly announced as data grid cell (localized).
-
Starting with the .NET Framework 4.7.1, screen readers announce the name of an editable(adj. 可编辑的) ComboBox.
-
In the .NET Framework 4.7 and earlier versions, PasswordBox controls were announced as “no item in view” or had otherwise incorrect behavior. This issue is fixed starting with the .NET Framework 4.7.1.
UIAutomation LiveRegion support
Screen readers such as Narrator help people read the UI contents of an application, usually by text-to-speech output of the UI content that has the focus. However, if a UI element changes and does not have the focus, the user may not be notified and may miss important information. Live regions aim at solving this problem. A developer can use them to inform(vt. 通知;告诉;报告) the screen reader or any other UIAutomation client that an important change has been made to a UI element. The screen reader can then decide how and when to inform the user of this change.
To support live regions, the following APIs have been added to WPF:
-
The AutomationElementIdentifiers.LiveSettingProperty and AutomationElementIdentifiers.LiveRegionChangedEvent fields, which identify the LiveSettingproperty and the LiveRegionChanged event. They can be set by using XAML.
-
The AutomationProperties.LiveSetting attached property, which informs the screen reader of the importance of the UI change to the user.
-
The AutomationProperties.LiveSettingProperty property, which identifies the AutomationProperties.LiveSetting attached property.
-
The AutomationPeer.GetLiveSettingCore method, which can be overridden(vt. 推翻;不顾;践踏) to provide a LiveSetting value.
-
The AutomationProperties.GetLiveSetting and AutomationProperties.SetLiveSetting methods, which get and set a LiveSetting value.
-
The System.Windows.Automation.AutomationLiveSetting enumeration(n. 列举;[数] 计算;细目), which defines the following possible LiveSetting values:
- AutomationLiveSetting.Off. The element does not send notifications if the content of the live region has changed.
-
AutomationLiveSetting.Polite. The element sends non-interruptive notifications if the content of the live region has changed.
- AutomationLiveSetting.Assertive. The element sends interruptive notifications if the content of the live region has changed.
You can create a LiveRegion by setting the AutomationProperties.LiveSetting property on the element of interest, as shown in the following example:
<TextBlock Name="myTextBlock" AutomationProperties.LiveSetting="Assertive">announcement</TextBlock>
When the data in the live region changes and you need to inform a screen reader, you explicitly raise an event, as shown in the following sample.
var peer = FrameworkElementAutomationPeer.FromElement(myTextBlock); peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
High contrast
Starting with the .NET Framework 4.7.1, improvements in high contrast have been made to various WPF controls. They are now visible when the HighContrast theme is set. These include:
-
Expander control
The focus visual for the Expander control is now visible. The keyboard visuals for ComboBox,ListBox, and RadioButton controls are visible as well. For example:
Before:
After:
-
CheckBox and RadioButton controls
The text in the CheckBox and RadioButton controls is now easier to see when selected in high contrast themes. For example:
Before:
After:
-
ComboBox control
Starting with the .NET Framework 4.7.1, the border of a disabled ComboBox control is the same color as disabled text. For example:
Before:
After:
In addition, disabled and focused buttons use the correct theme color.
Before:
After:
Finally, in the .NET Framework 4.7 and earlier versions, setting a ComboBox control’s style to
Toolbar.ComboBoxStyleKey
caused the drop-down arrow to be invisible. This issue is fixed starting with the .NET Framework 4.7.1. For example:Before:
After:
-
DataGrid control
Starting with the .NET Framework 4.7.1, the sort indicator arrow in DataGrid controls now uses correct theme colors. For example:
Before:
After:
In addition, in the .NET Framework 4.7 and earlier versions, the default link style changed to an incorrect color on mouse over in high contrast modes. This is resolved starting with the .NET Framework 4.7.1. Similarly, DataGrid checkbox columns uses the expected colors for keyboard focus feedback starting with the .NET Framework 4.7.1.
Before:
After:
For more information on WPF accessibility improvements in the .NET Framework 4.7.1, see Accessibility improvements in WPF.
Windows Forms accessibility improvements
In the .NET Framework 4.7.1, Windows Forms (WinForms) includes accessibility changes in the following areas.
Improved display in High Contrast mode
Starting with the .NET Framework 4.7.1, various WinForms controls offer improved rendering in the HighContrast modes available in the operating system. Windows 10 has changed the values for some high contrast system colors, and Windows Forms is based on the Windows 10 Win32 framework. For the best experience, run on the latest version of Windows and opt in to the latest OS changes by adding an app.manifest(vt. 证明,表明;显示) file in a test application and un-comment the Windows 10 supported OS line so that it looks the following:
<!-- Windows 10 --> <supportedOS Id=”{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}” />
Some examples of high contrast changes include:
-
Checkmarks in MenuStrip items are easier to view.
-
When selected, disabled MenuStrip items are easier to view.
-
Text in a selected Button control contrasts with the selection color.
-
Disabled text is easier to read. For example:
Before:
After:
-
High contrast improvements in the Thread Exception Dialog.
Improved Narrator support
Windows Forms in the .NET Framework 4.7.1 includes the following accessibility improvements for the Narrator:
-
The MonthCalendar control can be accessed by the Narrator, as well as by other UI automation tools.
-
The CheckedListBox control notifies Narrator when an item's check state has changed so the user is notified that they’ve changed the value of a list item.
-
The DataGridViewCell control reports the correct read-only status to Narrator.
-
Narrator can now read disabled ToolStripMenuItem text, whereas(conj. 然而;鉴于;反之) previously it would skip over disabled menu items.
Enhanced support for UIAutomation accessibility patterns
Starting with the .NET Framework 4.7.1, developers of accessibility technology tools can leverage common API accessibility patterns and properties for several WinForms controls. These accessibility improvements include:
-
The ComboBox and ToolStripSplitButton now support the expand/collapse pattern.
-
The DataGridViewCheckBoxCell now supports the toggle pattern.
-
The ToolStripItem control supports the Name property and the expand/collapse pattern.
-
The NumericUpDown and DomainUpDown controls support the Name property.
Improved property browser experience
Starting with the .NET Framework 4.7.1, Windows Forms includes:
- Better keyboard navigation through the various drop-down selection windows.
- A reduction of unnecessary tab stops.
- Better reporting of control types.
- Improved narrator behavior.
ASP.NET web controls
Starting with the .NET Framework 4.7.1 and Visual Studio 2017 15.3, ASP.NET improves how ASP.NET web controls work with accessibility technology in Visual Studio. Changes include the following:
-
Changes to implement missing UI accessibility patterns in controls, like the Add Field dialog in the Details View wizard, or the Configure ListView dialog of the ListView wizard.
-
Changes to improve the display in High Contrast mode, like the Data Pager Fields Editor.
-
Changes to improve the keyboard navigation experiences for controls, like the Fields dialog in the Edit Pager Fields wizard of the DataPager control, the Configure ObjectContext dialog, or the Configure Data Selection dialog of the Configure Data Source wizard.
.NET SDK Tools
The Configuration Editor Tool (SvcConfigEditor.exe) and Service Trace Viewer Tool (SvcTraceViewer.exe) have been improved by fixing varied accessibility issues. Most of these were small issues, like a name not being defined or certain UI automation patterns not being implemented correctly. While many users won’t be aware of these incorrect values, customers who use assistive technologies like screen readers will find these SDK tools more accessible.
These enhancements change some previous behaviors, such as keyboard focus order.
Windows Workflow Foundation (WF) Workflow Designer
Accessibility changes in the Workflow Designer include the following:
-
The tab order changes to left to right and top to bottom in some controls:
-
The initialize correlation window for setting correlation data for the InitializeCorrelationactivity.
-
The content definition window for the Receive, Send, SendReply, and ReceiveReply activities.
-
-
More functions are available via the keyboard:
-
When editing the properties of an activity, property groups can be collapsed by keyboard the first time they are focused.
-
Warning icons are accessible by keyboard.
-
The More Properties button in the Properties window is accessible by keyboard.
-
Keyboard users can access the header items in the Arguments and Variables panes(n. 窗格;边;面;窗格玻璃;嵌板) of the Workflow Designer.
-
-
Improved visibility of items with focus, such as when:
-
Adding rows to data grids used by the Workflow Designer and activity designers.
-
Tabbing through fields in the ReceiveReply and SendReply activities.
-
Setting default values for variables or arguments
-
Screen readers can now correctly recognize:
-
Breakpoints set in the workflow designer.
-
The FlowSwitch<T>, FlowDecision, and CorrelationScope activities.
-
The contents of the Receive activity.
-
The Target Type for the InvokeMethod activity.
-
The Exception combo box and the Finally section in the TryCatch activity.
-
The Message Type combo box, the splitter in the Add Correlation Initializers window, the Content Definition window, and the CorrelatesOn Definition window in the messaging activities (Receive, Send, SendReply, and ReceiveReply).
- State machine transitions(n. 过渡,转变) and transitions destinations(n. 目的地,终点;).
- Annotations(释文;注释) and connectors on FlowDecision activities.
- The context (right-click) menus for activities.
- The property value editors, the Clear Search button, the By Category and Alphabetical(adj. 字母的;[计] 依字母顺序的) sort buttons, and the Expression Editor dialog in the properties grid.
- The zoom percentage in the Workflow Designer.
- The separator in Parallel and Pick activities.
- The InvokeDelegate(vt. 委派…为代表;n. 代表) activity.
- The Select Types window for dictionary activities (
Microsoft.Activities.AddToDictionary<TKey,TValue>
,Microsoft.Activities.RemoveFromDictionary<TKey,TValue>
, etc.). - The Browse and Select .NET Type window.
- Breadcrumbs(n. 面包碎屑;vt. 在…上覆以面包屑) in the Workflow Designer.
-
-
Users who choose High Contrast themes will see many improvements in the visibility of the Workflow Designer and its controls, like better contrast ratios between elements and more noticeable selection boxes used for focus elements.