-
-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix screen reader issues with CardAction/Button/MenuItem/NavigationVi…
…ewItem (#1235) * Add narration support to CardAction * Fix screen readers trying to read IconElement in some cases * Add narration support to NavigationViewItem * Button workaround appears to be unnecessary now
- Loading branch information
1 parent
cfe9496
commit 83763fe
Showing
5 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/Wpf.Ui/Controls/CardAction/CardActionAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||
// Copyright (C) Leszek Pomianowski and WPF UI Contributors. | ||
// All Rights Reserved. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Automation; | ||
using System.Windows.Automation.Peers; | ||
|
||
namespace Wpf.Ui.Controls; | ||
|
||
internal class CardActionAutomationPeer : FrameworkElementAutomationPeer | ||
{ | ||
private readonly CardAction _owner; | ||
|
||
public CardActionAutomationPeer(CardAction owner) | ||
: base(owner) | ||
{ | ||
_owner = owner; | ||
} | ||
|
||
protected override string GetClassNameCore() | ||
{ | ||
return "Button"; | ||
} | ||
|
||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.Button; | ||
} | ||
|
||
public override object GetPattern(PatternInterface patternInterface) | ||
{ | ||
if (patternInterface == PatternInterface.ItemContainer) | ||
{ | ||
return this; | ||
} | ||
|
||
return base.GetPattern(patternInterface); | ||
} | ||
|
||
protected override AutomationPeer GetLabeledByCore() | ||
{ | ||
if (_owner.Content is UIElement element) | ||
{ | ||
return CreatePeerForElement(element); | ||
} | ||
|
||
return base.GetLabeledByCore(); | ||
} | ||
|
||
protected override string GetNameCore() | ||
{ | ||
var result = base.GetNameCore() ?? string.Empty; | ||
|
||
if (result == string.Empty) | ||
{ | ||
result = AutomationProperties.GetName(_owner); | ||
} | ||
|
||
if (result == string.Empty && _owner.Content is DependencyObject d) | ||
{ | ||
result = AutomationProperties.GetName(d); | ||
} | ||
|
||
if (result == string.Empty && _owner.Content is string s) | ||
{ | ||
result = s; | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/Wpf.Ui/Controls/NavigationView/NavigationViewItemAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||
// Copyright (C) Leszek Pomianowski and WPF UI Contributors. | ||
// All Rights Reserved. | ||
|
||
using System.Windows.Automation; | ||
using System.Windows.Automation.Peers; | ||
|
||
namespace Wpf.Ui.Controls; | ||
|
||
internal class NavigationViewItemAutomationPeer : FrameworkElementAutomationPeer | ||
{ | ||
private readonly NavigationViewItem _owner; | ||
|
||
public NavigationViewItemAutomationPeer(NavigationViewItem owner) | ||
: base(owner) | ||
{ | ||
_owner = owner; | ||
} | ||
|
||
protected override string GetClassNameCore() | ||
{ | ||
return "NavigationItem"; | ||
} | ||
|
||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.TabItem; | ||
} | ||
|
||
public override object GetPattern(PatternInterface patternInterface) | ||
{ | ||
if (patternInterface == PatternInterface.ItemContainer) | ||
{ | ||
return this; | ||
} | ||
|
||
return base.GetPattern(patternInterface); | ||
} | ||
|
||
protected override AutomationPeer GetLabeledByCore() | ||
{ | ||
if (_owner.Content is UIElement element) | ||
{ | ||
return CreatePeerForElement(element); | ||
} | ||
|
||
return base.GetLabeledByCore(); | ||
} | ||
|
||
protected override string GetNameCore() | ||
{ | ||
var result = base.GetNameCore() ?? string.Empty; | ||
|
||
if (result == string.Empty) | ||
{ | ||
result = AutomationProperties.GetName(_owner); | ||
} | ||
|
||
if (result == string.Empty && _owner.Content is DependencyObject d) | ||
{ | ||
result = AutomationProperties.GetName(d); | ||
} | ||
|
||
if (result == string.Empty && _owner.Content is string s) | ||
{ | ||
result = s; | ||
} | ||
|
||
return result; | ||
} | ||
} |