Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 5 additions & 44 deletions src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Windows.Automation;
using System.Windows.Automation.Peers;
using Wpf.Ui.Controls;

Expand All @@ -12,8 +11,12 @@ namespace Wpf.Ui.AutomationPeers;
/// <summary>
/// Provides UI Automation peer for the CardControl.
/// </summary>
internal class CardControlAutomationPeer(CardControl owner) : FrameworkElementAutomationPeer(owner)
internal class CardControlAutomationPeer : FrameworkElementAutomationPeer
{
public CardControlAutomationPeer(CardControl owner)
: base(owner)
{ }

protected override string GetClassNameCore()
{
return "CardControl";
Expand All @@ -23,46 +26,4 @@ protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Pane;
}

public override object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.ItemContainer)
{
return this;
}

return base.GetPattern(patternInterface);
}

protected override AutomationPeer GetLabeledByCore()
{
if (owner.Header 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.Header is DependencyObject d)
{
result = AutomationProperties.GetName(d);
}

if (result == string.Empty && owner.Header is string s)
{
result = s;
}

return result;
}
}
5 changes: 4 additions & 1 deletion src/Wpf.Ui/Controls/CardAction/CardAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

// ReSharper disable once CheckNamespace
using System.Windows.Automation.Peers;
using System.Windows.Controls.Primitives;

namespace Wpf.Ui.Controls;

/// <summary>
/// Inherited from the <see cref="System.Windows.Controls.Primitives.ButtonBase"/> interactive card styled according to Fluent Design.
/// </summary>
public class CardAction : System.Windows.Controls.Primitives.ButtonBase
public class CardAction : ButtonBase
{
/// <summary>Identifies the <see cref="IsChevronVisible"/> dependency property.</summary>
public static readonly DependencyProperty IsChevronVisibleProperty = DependencyProperty.Register(
Expand Down Expand Up @@ -55,4 +56,6 @@ protected override AutomationPeer OnCreateAutomationPeer()
{
return new CardActionAutomationPeer(this);
}

internal void AutomationClick() => this.OnClick();
}
51 changes: 14 additions & 37 deletions src/Wpf.Ui/Controls/CardAction/CardActionAutomationPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@
// 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;
using System.Windows.Automation.Provider;
using System.Windows.Threading;

namespace Wpf.Ui.Controls;

internal class CardActionAutomationPeer : FrameworkElementAutomationPeer
internal class CardActionAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider
{
private readonly CardAction _owner;

public CardActionAutomationPeer(CardAction owner)
: base(owner)
{
_owner = owner;
}
{ }

protected override string GetClassNameCore()
{
Expand All @@ -35,43 +28,27 @@ protected override AutomationControlType GetAutomationControlTypeCore()

public override object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.ItemContainer)
if (patternInterface == PatternInterface.Invoke)
{
return this;
}

return base.GetPattern(patternInterface);
}

protected override AutomationPeer GetLabeledByCore()
void IInvokeProvider.Invoke()
{
if (_owner.Content is UIElement element)
if (!IsEnabled())
{
return CreatePeerForElement(element);
throw new ElementNotEnabledException();
}

return base.GetLabeledByCore();
}

protected override string GetNameCore()
{
var result = base.GetNameCore() ?? string.Empty;

if (result == string.Empty)
// Async call of click event
// In ClickHandler opens a dialog and suspend the execution we don't want to block this thread
Dispatcher.BeginInvoke(DispatcherPriority.Input, new DispatcherOperationCallback(_ =>
{
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;
((CardAction)Owner).AutomationClick();
return null;
}), null);
}
}
Loading