maui
maui copied to clipboard
[Windows] - Picker on windows shows "Microsoft.Maui.Controls.Picker" if ItemsSource has an empty string
Root Cause
When there is a binding error or the element cannot resolve a binding issue, the ToString() override method is called. As a result, 'Microsoft.Maui.Controls.Picker' is displayed in the view.
Description of Change
Removing the DataContext and setting the Picker title to the native combo box in UpdateTitle() will resolve the issue.
Reference
Referred from possible fixes - https://github.com/dotnet/maui/issues/8845#issue-1309978675
Issues Fixed
Fixes #8845
Output
Before
https://github.com/user-attachments/assets/f4f1be51-d780-4cd1-af5d-a34cc0671c3c
After
https://github.com/user-attachments/assets/cfd40a04-357d-4c6b-baea-3dba01f001a8
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Azure Pipelines successfully started running 3 pipeline(s).
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Azure Pipelines successfully started running 3 pipeline(s).
Azure Pipelines successfully started running 3 pipeline(s).
I do really like the removal of the someone scary "just set the data context to the picker itself" concept...
However, I see the
ComboBoxHeadertemplate has bindings:<DataTemplate x:Key="ComboBoxHeader"> <TextBlock Text="{Binding Title}" CharacterSpacing="{Binding Path=CharacterSpacing, ElementName=HeaderContentPresenter}" Foreground="{Binding TitleColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}" /> </DataTemplate>Do those still work? Not sure if we have tests for those. If we do, then this PR is all green and happy, if not, please add a test that makes sure the foreground/character spacing is respected.
I am wondering if this template should be updated to actually bind to the templated parent instead of just to
{Binding}. If the character spacing and foreground still work, then I will be having to go back to my XAML 101, but I think some sort of parent-based binding may actually solve this without the data context being needed. But I am not sure of the latter.
The previous changes broke the header template bindings. We have now updated the fixes by setting the picker title to the native combo box header, as the header template's data context is the header itself, allowing it to bind correctly.
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/rebase
/rebase
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).