Skip to content

Commit

Permalink
Sets Automatin Size and position in set for MenuBar (#6827)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkudiess authored Mar 16, 2022
1 parent c8d9c51 commit 0e14e8b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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

0 comments on commit 0e14e8b

Please sign in to comment.