-
-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add narration support to NavigationViewItem
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
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
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; | ||
} | ||
} |