From f536856f5b453eee19197f34c8da9db42335f50a Mon Sep 17 00:00:00 2001 From: Dominik Titl <78549750+morning4coffe-dev@users.noreply.github.com> Date: Sat, 30 Mar 2024 11:08:56 +0100 Subject: [PATCH] feat: Implement `FlipViewAutomationPeer` --- .../Peers/FlipViewAutomationPeer.cs | 66 +++++++++++++++++++ .../UI/Xaml/Controls/FlipView/FlipView.cs | 6 ++ 2 files changed, 72 insertions(+) create mode 100644 src/Uno.UI/UI/Xaml/Automation/Peers/FlipViewAutomationPeer.cs diff --git a/src/Uno.UI/UI/Xaml/Automation/Peers/FlipViewAutomationPeer.cs b/src/Uno.UI/UI/Xaml/Automation/Peers/FlipViewAutomationPeer.cs new file mode 100644 index 000000000000..b53c047bfe83 --- /dev/null +++ b/src/Uno.UI/UI/Xaml/Automation/Peers/FlipViewAutomationPeer.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. +// MUX Reference FlipViewAutomationPeer_Partial.cpp, tag winui3/release/1.5-stable + +using System.Collections.Generic; + +namespace Microsoft.UI.Xaml.Automation.Peers; + +/// +/// Exposes FlipView types to Microsoft UI Automation. +/// +public partial class FlipViewAutomationPeer : SelectorAutomationPeer +{ + public FlipViewAutomationPeer(Controls.FlipView owner) : base(owner) + { + + } + + protected override IList GetChildrenCore() + { + var children = base.GetChildrenCore(); + + if ((Owner as Controls.FlipView).SelectedItem is { } selectedItem) + { + var itemPeer = CreateItemAutomationPeer(selectedItem); + + if (itemPeer is { }) + { + var itemPeerAsAP = itemPeer as AutomationPeer; + children.Add(itemPeerAsAP); + + if (children is { }) + { + (var previousButton, var nextButton) = (Owner as Controls.FlipView).GetPreviousAndNextButtons(); + + if (nextButton is { }) + { + var nextButtonAP = nextButton.GetOrCreateAutomationPeer(); + + if (nextButtonAP is { }) + { + children.Insert(0, nextButtonAP); + } + } + if (previousButton is { }) + { + var previousButtonAP = previousButton.GetOrCreateAutomationPeer(); + + if (previousButtonAP is { }) + { + children.Insert(0, previousButtonAP); + } + } + } + } + } + + return children; + } + + protected override string GetClassNameCore() => nameof(Controls.FlipView); + + protected override AutomationControlType GetAutomationControlTypeCore() + => AutomationControlType.List;//UNO TODO: AutomationControlType.FlipView; + +} diff --git a/src/Uno.UI/UI/Xaml/Controls/FlipView/FlipView.cs b/src/Uno.UI/UI/Xaml/Controls/FlipView/FlipView.cs index 83e32d717f3f..451892588b52 100644 --- a/src/Uno.UI/UI/Xaml/Controls/FlipView/FlipView.cs +++ b/src/Uno.UI/UI/Xaml/Controls/FlipView/FlipView.cs @@ -30,5 +30,11 @@ public bool UseTouchAnimationsForAllNavigation DependencyProperty.Register("UseTouchAnimationsForAllNavigation", typeof(bool), typeof(FlipView), new FrameworkPropertyMetadata(true)); partial void InitializePartial(); + + internal (ButtonBase previousButton, ButtonBase nextButton) GetPreviousAndNextButtons() + { + // UNO TODO: Implement GetPreviousAndNextButtons on FlipView + return (null, null); + } } }