Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuBar: Sets Automation Size of Set and Position in Set #6827

Merged
merged 1 commit into from
Mar 16, 2022
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
37 changes: 37 additions & 0 deletions dev/MenuBar/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ MenuBar::MenuBar()

auto items = winrt::make<ObservableVector<winrt::MenuBarItem>>();
SetValue(s_ItemsProperty, items);

auto observableVector = Items().try_as<winrt::IObservableVector<winrt::MenuBarItem>>();
m_itemsVectorChangedRevoker = observableVector.VectorChanged(winrt::auto_revoke,
{
[this](auto const&, auto const&)
{
UpdateAutomationSizeAndPosition();
}
});
}

// IUIElement / IUIElementOverridesHelper
Expand Down Expand Up @@ -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<winrt::UIElement>())
{
if (itemAsUIElement.Visibility() == winrt::Visibility::Visible)
{
sizeOfSet++;
winrt::AutomationProperties::SetPositionInSet(itemAsUIElement, sizeOfSet);
}
}
}

for (const auto& item : Items())
{
if (auto itemAsUIElement = item.try_as<winrt::UIElement>())
{
if (itemAsUIElement.Visibility() == winrt::Visibility::Visible)
{
winrt::AutomationProperties::SetSizeOfSet(itemAsUIElement, sizeOfSet);
}
}
}
}
2 changes: 2 additions & 0 deletions dev/MenuBar/MenuBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class MenuBar :
private:

void SetUpTemplateParts();
void UpdateAutomationSizeAndPosition();

bool m_isFlyoutOpen{ false };
winrt::IObservableVector<winrt::MenuBarItem>::VectorChanged_revoker m_itemsVectorChangedRevoker{};

// Visual components
tracker_ref<winrt::ItemsControl> m_contentRoot{ this };
Expand Down