Bound ComboBox within a page and frame not working as expected - WinUI 3

youki 996 Reputation points
2023-01-24T18:47:43.97+00:00

Hi,

i have a bound ComboBox which i've already posted here.

I'm adding a separator by a TemplateSelector but to disable the separator, I have to iterate the ComboBoxItems in the Tapped event and set the IsEnabled property to false. This has to be happened in the Tapped event because this is the only event where the items are already rendered, I guess.

This is in MainWindow.xaml and is working great.

Now I have the exact same code on another page (SelectFunction.xaml) which is opened by a frame in MainWindow.xaml but the Tapped event is not working as expected like in MainWindow.xaml. The event gets only sporadically fired, mostly only, if you click near the area of the arrow. It's weird. I've tried a few things from posts where people had similar problems:

  • setting a background on the Frame/ ComboBox
  • setting the isHitTestVisible property
  • isSynchronizeWithCurrentItem (this throws an error when opening the ComboBox)

Further, even if i can disable iterate the items i can't get the item as before with ItemContainerGenerator because i get an Access Violation and the item is null even, if I can get the values by casting.

I've tried to change the ComboBox Access by using the name, casting the sender, getting it by a static instance of the page (winrt::App1::implementation::SelectFunction* SelectFunction::s_selectFunction;)

I've added the items from code behind at first because and it's only text that i would need no template. It works great but it's not that practical, so i changed to binding.

From code behind like so but really ugly, if i have 30 items and it's dynamically changing:

winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem cmbi0;
cmbi0.Name(L"cmbiNoAction");
cmbi0.Content(winrt::box_value(L"Keine Aktion"));
cmbFunction().Items().Append(winrt::box_value(cmbi0));

winrt::Microsoft::UI::Xaml::Controls::NavigationViewItemSeparator separator1;

winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem cmbiA;
cmbiA.IsEnabled(false);
cmbiA.Content(winrt::box_value(separator1));
cmbFunction().Items().Append(winrt::box_value(cmbiA));

winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem cmbi1;
cmbi1.Content(winrt::box_value(L"Category1"));
cmbi1.IsEnabled(false);
cmbFunction().Items().Append(winrt::box_value(cmbi1));

It looks like a WinUi 3 bug to me, what are you thinking?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
727 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,544 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
767 questions
{count} votes