Skip to content

Commit

Permalink
Adding automation peer for ToggleButton #647
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Nov 12, 2018
1 parent c27c046 commit 4c22e96
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Fluent.Ribbon/Automation/Peers/ButtonAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace Fluent.Automation.Peers
{
using JetBrains.Annotations;
using Button = Fluent.Button;


/// <inheritdoc />
public class ButtonAutomationPeer : System.Windows.Automation.Peers.ButtonAutomationPeer
{
Expand Down
32 changes: 32 additions & 0 deletions Fluent.Ribbon/Automation/Peers/ToggleButtonAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Fluent.Automation.Peers
{
using JetBrains.Annotations;

/// <inheritdoc />
public class ToggleButtonAutomationPeer : System.Windows.Automation.Peers.ToggleButtonAutomationPeer
{
/// <summary>Initializes a new instance of the <see cref="T:TextBoxAutomationPeer" /> class.</summary>
/// <param name="owner">The element associated with this automation peer.</param>
public ToggleButtonAutomationPeer([NotNull] ToggleButton owner)
: base(owner)
{
}

/// <inheritdoc />
protected override string GetNameCore()
{
var text = base.GetNameCore();
var owner = (IHeaderedControl)this.Owner;

if (string.IsNullOrEmpty(text))
{
if (owner.Header is string headerString)
{
return headerString;
}
}

return text;
}
}
}
7 changes: 7 additions & 0 deletions Fluent.Ribbon/Controls/ToggleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Fluent
{
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Data;
using System.Windows.Markup;
using Fluent.Internal.KnownBoxes;
Expand Down Expand Up @@ -279,5 +280,11 @@ void ILogicalChildSupport.RemoveLogicalChild(object child)
{
this.RemoveLogicalChild(child);
}

/// <inheritdoc />
protected override AutomationPeer OnCreateAutomationPeer()
{
return new Fluent.Automation.Peers.ToggleButtonAutomationPeer(this);
}
}
}

0 comments on commit 4c22e96

Please sign in to comment.