Skip to content

Commit 20cac25

Browse files
fix: Workaround XAML bug with ComboBox and dark theme (#380)
1 parent b823b7b commit 20cac25

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

windows/ReactNativePicker/ReactPickerView.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <winrt/Windows.Foundation.Metadata.h>
1010
#include <UI.Xaml.Input.h>
11+
#include <UI.Xaml.Media.h>
1112

1213
namespace winrt {
1314
using namespace Microsoft::ReactNative;
@@ -50,6 +51,20 @@ namespace winrt::ReactNativePicker::implementation {
5051
winrt::FocusManager::TryFocusAsync(comboBox, winrt::FocusState::Programmatic);
5152
}
5253
});
54+
55+
// Workaround XAML bug with ComboBox and dark theme. Same as:
56+
// https://github.com/microsoft/microsoft-ui-xaml/issues/2331
57+
m_dropDownOpenedRevoker = this->DropDownOpened(winrt::auto_revoke,
58+
[](auto const& sender, auto const& /*args*/) {
59+
auto comboBox = sender.as<xaml::Controls::ComboBox>();
60+
if (comboBox.XamlRoot()) { // XamlRoot added in 19H1
61+
auto comboBoxAsFrameworkElement = comboBox.XamlRoot().Content().try_as<xaml::FrameworkElement>();
62+
auto popups = xaml::Media::VisualTreeHelper::GetOpenPopupsForXamlRoot(comboBox.XamlRoot());
63+
for (auto const& popup : popups) {
64+
popup.Child().as<xaml::FrameworkElement>().RequestedTheme(comboBoxAsFrameworkElement.ActualTheme());
65+
}
66+
}
67+
});
5368
}
5469

5570
void ReactPickerView::UpdateProperties(winrt::IJSValueReader const& reader) {

windows/ReactNativePicker/ReactPickerView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace winrt::ReactNativePicker::implementation {
2525
xaml::Media::Brush m_comboBoxColor{ nullptr };
2626
xaml::Controls::ComboBox::SelectionChanged_revoker m_selectionChangedRevoker{};
2727
xaml::Controls::ComboBox::DropDownClosed_revoker m_dropDownClosedRevoker{};
28+
xaml::Controls::ComboBox::DropDownOpened_revoker m_dropDownOpenedRevoker{};
2829

2930
void RegisterEvents();
3031
void RepopulateItems(winrt::Microsoft::ReactNative::JSValueArray const& items);

0 commit comments

Comments
 (0)