maui icon indicating copy to clipboard operation
maui copied to clipboard

[Windows] - Picker on windows shows "Microsoft.Maui.Controls.Picker" if ItemsSource has an empty string

Open NirmalKumarYuvaraj opened this issue 1 year ago • 4 comments

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

NirmalKumarYuvaraj avatar Aug 16 '24 09:08 NirmalKumarYuvaraj

/azp run

PureWeen avatar Aug 18 '24 17:08 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Aug 18 '24 17:08 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Aug 26 '24 14:08 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Aug 30 '24 10:08 azure-pipelines[bot]

/azp run

rmarinho avatar Aug 30 '24 10:08 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Aug 30 '24 10:08 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Sep 02 '24 13:09 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 04 '24 08:10 azure-pipelines[bot]

I do really like the removal of the someone scary "just set the data context to the picker itself" concept...

However, I see the ComboBoxHeader template 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.

NirmalKumarYuvaraj avatar Oct 04 '24 10:10 NirmalKumarYuvaraj

/azp run

PureWeen avatar Oct 07 '24 20:10 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 07 '24 20:10 azure-pipelines[bot]

/rebase

NirmalKumarYuvaraj avatar Oct 11 '24 09:10 NirmalKumarYuvaraj

/rebase

NirmalKumarYuvaraj avatar Oct 11 '24 09:10 NirmalKumarYuvaraj

/azp run

jsuarezruiz avatar Oct 11 '24 11:10 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 11 '24 11:10 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 14 '24 10:10 azure-pipelines[bot]

/azp run

PureWeen avatar Oct 15 '24 16:10 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 15 '24 16:10 azure-pipelines[bot]