Skip to content

Commit

Permalink
Fixes #768 by adding automation peer for TwoLineLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Jan 22, 2020
1 parent 1aae3b6 commit 205942a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [#758](../../issues/758) - Auto menu expanding not working for MenuItems with ItemSource binding
- [#765](../../issues/765) - InRibbonGallery Resizing Issues
- [#766](../../issues/766) - Resizing of InRibbonGallery in a DataTemplate does not work
- [#768](../../issues/768) - Accessibility Insights: "An onscreen element must not have a null"

- ### Enhancements/Features
- Many automation peers have been added and improved
Expand Down
72 changes: 72 additions & 0 deletions Fluent.Ribbon/Automation/Peers/TwoLineLabelAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
namespace Fluent.Automation.Peers
{
using System.Collections.Generic;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Controls;

/// <summary>
/// <see cref="AutomationPeer"/> for <see cref="TwoLineLabel"/>.
/// </summary>
public class TwoLineLabelAutomationPeer : FrameworkElementAutomationPeer
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="owner">Owner of the AutomationPeer.</param>
public TwoLineLabelAutomationPeer(TwoLineLabel owner)
: base(owner)
{
}

/// <summary>
/// <see cref="AutomationPeer.GetChildrenCore"/>
/// </summary>
protected override List<AutomationPeer> GetChildrenCore()
{
return null;
}

/// <summary>
/// <see cref="AutomationPeer.GetAutomationControlTypeCore"/>
/// </summary>
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Text;
}

/// <summary>
/// <see cref="AutomationPeer.GetClassNameCore"/>
/// </summary>
/// <returns></returns>
protected override string GetClassNameCore()
{
return "TwoLineLabel";
}

/// <inheritdoc />
protected override string GetNameCore()
{
return ((TwoLineLabel)this.Owner).Text;
}

/// <summary>
/// <see cref="AutomationPeer.IsControlElementCore"/>
/// </summary>
protected override bool IsControlElementCore()
{
// Return false if TwoLineLabel is part of a ControlTemplate, otherwise return the base method
var tb = (TwoLineLabel)this.Owner;
var templatedParent = tb.TemplatedParent;

// If the templatedParent is a ContentPresenter, this TextBlock is generated from a DataTemplate
if (templatedParent == null
|| templatedParent is ContentPresenter)
{
return base.IsControlElementCore();
}

return false;
}
}
}
4 changes: 4 additions & 0 deletions Fluent.Ribbon/Controls/TwoLineLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Fluent
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Markup;
using Fluent.Internal.KnownBoxes;
Expand Down Expand Up @@ -124,6 +125,9 @@ public override void OnApplyTemplate()
this.UpdateTextRun();
}

/// <inheritdoc />
protected override AutomationPeer OnCreateAutomationPeer() => new Fluent.Automation.Peers.TwoLineLabelAutomationPeer(this);

#endregion

#region Event handling
Expand Down

0 comments on commit 205942a

Please sign in to comment.