From 0e14e8bc8e3124f2d05f97ac4c66cad7356aeeba Mon Sep 17 00:00:00 2001 From: Barbara Kudiess Date: Wed, 16 Mar 2022 06:54:14 -0700 Subject: [PATCH] Sets Automatin Size and position in set for MenuBar (#6827) --- dev/MenuBar/MenuBar.cpp | 37 +++++++++++++++++++++++++++++++++++++ dev/MenuBar/MenuBar.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/dev/MenuBar/MenuBar.cpp b/dev/MenuBar/MenuBar.cpp index 40d90b2dab..c89997e7db 100644 --- a/dev/MenuBar/MenuBar.cpp +++ b/dev/MenuBar/MenuBar.cpp @@ -15,6 +15,15 @@ MenuBar::MenuBar() auto items = winrt::make>(); SetValue(s_ItemsProperty, items); + + auto observableVector = Items().try_as>(); + m_itemsVectorChangedRevoker = observableVector.VectorChanged(winrt::auto_revoke, + { + [this](auto const&, auto const&) + { + UpdateAutomationSizeAndPosition(); + } + }); } // IUIElement / IUIElementOverridesHelper @@ -60,3 +69,31 @@ void MenuBar::IsFlyoutOpen(bool state) m_isFlyoutOpen = state; } +// Automation Properties +void MenuBar::UpdateAutomationSizeAndPosition() +{ + int sizeOfSet = 0; + + for (const auto& item : Items()) + { + if (auto itemAsUIElement = item.try_as()) + { + if (itemAsUIElement.Visibility() == winrt::Visibility::Visible) + { + sizeOfSet++; + winrt::AutomationProperties::SetPositionInSet(itemAsUIElement, sizeOfSet); + } + } + } + + for (const auto& item : Items()) + { + if (auto itemAsUIElement = item.try_as()) + { + if (itemAsUIElement.Visibility() == winrt::Visibility::Visible) + { + winrt::AutomationProperties::SetSizeOfSet(itemAsUIElement, sizeOfSet); + } + } + } +} \ No newline at end of file diff --git a/dev/MenuBar/MenuBar.h b/dev/MenuBar/MenuBar.h index 6937bebfe9..7df8bca849 100644 --- a/dev/MenuBar/MenuBar.h +++ b/dev/MenuBar/MenuBar.h @@ -27,8 +27,10 @@ class MenuBar : private: void SetUpTemplateParts(); + void UpdateAutomationSizeAndPosition(); bool m_isFlyoutOpen{ false }; + winrt::IObservableVector::VectorChanged_revoker m_itemsVectorChangedRevoker{}; // Visual components tracker_ref m_contentRoot{ this };