diff --git a/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs b/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs
index 185b09c78..54c97a87c 100644
--- a/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs
+++ b/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs
@@ -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;
@@ -12,8 +11,12 @@ namespace Wpf.Ui.AutomationPeers;
///
/// Provides UI Automation peer for the CardControl.
///
-internal class CardControlAutomationPeer(CardControl owner) : FrameworkElementAutomationPeer(owner)
+internal class CardControlAutomationPeer : FrameworkElementAutomationPeer
{
+ public CardControlAutomationPeer(CardControl owner)
+ : base(owner)
+ { }
+
protected override string GetClassNameCore()
{
return "CardControl";
@@ -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;
- }
}
diff --git a/src/Wpf.Ui/Controls/CardAction/CardAction.cs b/src/Wpf.Ui/Controls/CardAction/CardAction.cs
index dac6f7554..ad6c49e11 100644
--- a/src/Wpf.Ui/Controls/CardAction/CardAction.cs
+++ b/src/Wpf.Ui/Controls/CardAction/CardAction.cs
@@ -5,13 +5,14 @@
// ReSharper disable once CheckNamespace
using System.Windows.Automation.Peers;
+using System.Windows.Controls.Primitives;
namespace Wpf.Ui.Controls;
///
/// Inherited from the interactive card styled according to Fluent Design.
///
-public class CardAction : System.Windows.Controls.Primitives.ButtonBase
+public class CardAction : ButtonBase
{
/// Identifies the dependency property.
public static readonly DependencyProperty IsChevronVisibleProperty = DependencyProperty.Register(
@@ -55,4 +56,6 @@ protected override AutomationPeer OnCreateAutomationPeer()
{
return new CardActionAutomationPeer(this);
}
+
+ internal void AutomationClick() => this.OnClick();
}
diff --git a/src/Wpf.Ui/Controls/CardAction/CardActionAutomationPeer.cs b/src/Wpf.Ui/Controls/CardAction/CardActionAutomationPeer.cs
index ffba11b5f..b774a936a 100644
--- a/src/Wpf.Ui/Controls/CardAction/CardActionAutomationPeer.cs
+++ b/src/Wpf.Ui/Controls/CardAction/CardActionAutomationPeer.cs
@@ -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()
{
@@ -35,7 +28,7 @@ protected override AutomationControlType GetAutomationControlTypeCore()
public override object GetPattern(PatternInterface patternInterface)
{
- if (patternInterface == PatternInterface.ItemContainer)
+ if (patternInterface == PatternInterface.Invoke)
{
return this;
}
@@ -43,35 +36,19 @@ public override object GetPattern(PatternInterface patternInterface)
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);
}
}