Skip to content

Commit

Permalink
Fixes #1125 (finally)
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Aug 2, 2023
1 parent c17bb0f commit 2165d04
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for Fluent.Ribbon

## 10.0.2

- ### Bug fixes

- [#1125](../../issues/1125) - BackStage Back Button doesn't have an accessibility text.

## 10.0.1

- ### Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions Fluent.Ribbon.Showcase/TestContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
<Grid>
<!-- Backstage items can be keytipped -->
<Fluent:Backstage x:Name="Backstage"
AutomationProperties.Name="Backstage"
IsOpen="{Binding IsBackstageOpen, Mode=TwoWay}"
Visibility="Collapsed">
<Fluent:Backstage.ToolTip>
Expand Down Expand Up @@ -317,6 +318,7 @@
</Fluent:Backstage>

<Fluent:ApplicationMenu x:Name="ApplicationMenu"
AutomationProperties.Name="Application menu"
Visibility="Collapsed">
<Fluent:ApplicationMenu.RightPaneContent>
<StackPanel HorizontalAlignment="Stretch"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Fluent.Automation.Peers;

using System.Collections.Generic;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using Fluent.Extensions;
using Fluent.Internal;

/// <summary>
/// Automation peer for <see cref="BackstageTabControl" />.
Expand Down Expand Up @@ -34,4 +37,22 @@ protected override ItemAutomationPeer CreateItemAutomationPeer(object item)
bool ISelectionProvider.IsSelectionRequired => true;

bool ISelectionProvider.CanSelectMultiple => false;

/// <inheritdoc />
protected override List<AutomationPeer> GetChildrenCore()
{
var baseResult = base.GetChildrenCore() ?? new List<AutomationPeer>();

if (this.OwningBackstageTabControl.BackButton is { } backButton)
{
var backButtonAutomationPeer = backButton.GetOrCreateAutomationPeer();

if (backButtonAutomationPeer is not null)
{
baseResult.Insert(0, backButtonAutomationPeer);
}
}

return baseResult;
}
}
35 changes: 28 additions & 7 deletions Fluent.Ribbon/Automation/Peers/RibbonTabControlAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace Fluent.Automation.Peers;

using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using Fluent.Extensions;
using Fluent.Internal;

/// <summary>
/// Automation peer for <see cref="RibbonTabControl"/>.
Expand Down Expand Up @@ -81,9 +84,29 @@ protected override List<AutomationPeer> GetChildrenCore()
{
var children = base.GetChildrenCore() ?? new List<AutomationPeer>();

var toolbarPanel = this.OwningRibbonTabControl.ToolbarPanel;
if (this.OwningRibbonTabControl.Menu is { } menu)
{
var automationPeer = menu.GetOrCreateAutomationPeer();

if (automationPeer is null)
{
var child = UIHelper.GetVisualChildren(menu)
.OfType<UIElement>()
.FirstOrDefault(x => x.IsVisible);

if (child is not null)
{
automationPeer = child.GetOrCreateAutomationPeer();
}
}

if (toolbarPanel is not null)
if (automationPeer is not null)
{
children.Insert(0, automationPeer);
}
}

if (this.OwningRibbonTabControl.ToolbarPanel is { } toolbarPanel)
{
foreach (UIElement? child in toolbarPanel.Children)
{
Expand All @@ -92,7 +115,7 @@ protected override List<AutomationPeer> GetChildrenCore()
continue;
}

var automationPeer = CreatePeerForElement(child);
var automationPeer = child.GetOrCreateAutomationPeer();

if (automationPeer is not null)
{
Expand All @@ -101,11 +124,9 @@ protected override List<AutomationPeer> GetChildrenCore()
}
}

var displayOptionsButton = this.OwningRibbonTabControl.DisplayOptionsControl;

if (displayOptionsButton is not null)
if (this.OwningRibbonTabControl.DisplayOptionsControl is { } displayOptionsButton)
{
var automationPeer = CreatePeerForElement(displayOptionsButton);
var automationPeer = displayOptionsButton.GetOrCreateAutomationPeer();

if (automationPeer is not null)
{
Expand Down
4 changes: 4 additions & 0 deletions Fluent.Ribbon/Controls/BackstageTabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Fluent;
/// </summary>
[TemplatePart(Name = "PART_SelectedContentHost", Type = typeof(ContentPresenter))]
[TemplatePart(Name = "PART_ItemsPanelContainer", Type = typeof(UIElement))]
[TemplatePart(Name = "PART_BackButton", Type = typeof(UIElement))]
public class BackstageTabControl : Selector, ILogicalChildSupport
{
#region Properties
Expand All @@ -29,6 +30,8 @@ public class BackstageTabControl : Selector, ILogicalChildSupport

internal UIElement? ItemsPanelContainer { get; private set; }

internal UIElement? BackButton { get; private set; }

/// <summary>Identifies the <see cref="BackButtonUid"/> dependency property.</summary>
public static readonly DependencyProperty BackButtonUidProperty = DependencyProperty.Register(
nameof(BackButtonUid), typeof(string), typeof(BackstageTabControl), new PropertyMetadata(default(string)));
Expand Down Expand Up @@ -329,6 +332,7 @@ public override void OnApplyTemplate()

this.ItemsPanelContainer = this.GetTemplateChild("PART_ItemsPanelContainer") as UIElement;
this.SelectedContentHost = this.GetTemplateChild("PART_SelectedContentHost") as ContentPresenter;
this.BackButton = this.GetTemplateChild("PART_BackButton") as UIElement;
}

/// <inheritdoc />
Expand Down
13 changes: 13 additions & 0 deletions Fluent.Ribbon/Extensions/UIElementExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Fluent.Extensions;

using System.Windows;
using System.Windows.Automation.Peers;

internal static class UIElementExtensions
{
public static AutomationPeer? GetOrCreateAutomationPeer(this UIElement element)
{
return UIElementAutomationPeer.FromElement(element)
?? UIElementAutomationPeer.CreatePeerForElement(element);
}
}
2 changes: 1 addition & 1 deletion Fluent.Ribbon/Themes/Controls/BackstageTabControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
VerticalAlignment="Top"
IsEnabled="{TemplateBinding IsWindowSteeringHelperEnabled}" />

<Button x:Name="backbutton"
<Button x:Name="PART_BackButton"
Uid="{TemplateBinding BackButtonUid}"
Style="{DynamicResource Fluent.Ribbon.Styles.BackstageBackButton}"
Grid.Row="0"
Expand Down

0 comments on commit 2165d04

Please sign in to comment.