dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

OnPlatform does not work in Header of CollectionView #25124

Open suugbut opened 1 month ago

suugbut commented 1 month ago

Description

The following works.

<CollectionView.ItemTemplate>
    <OnPlatform x:TypeArguments="DataTemplate">
        <On Platform="Android">
            <DataTemplate>
                <Label Text="{Binding .}" />
            </DataTemplate>
        </On>
        <On Platform="WinUI">
            <DataTemplate>
                <Label Text="{Binding .}" BackgroundColor="Red" />
            </DataTemplate>
        </On>
    </OnPlatform>
</CollectionView.ItemTemplate>

However the following does NOT work on both Windows and Android.

<CollectionView.Header>
     <OnPlatform x:TypeArguments="View">
             <On Platform="Android">
                 <Label Text="Android" />
             </On>
             <On Platform="WinUI">
                 <Label Text="WinUI" />
             </On>
     </OnPlatform>
</CollectionView.Header>

Steps to Reproduce

  1. Create a project from the default MAUI template.
  2. Use the following for the XAML of MainPage. Remove the unnecessary code in the default MainPage.cs.
    <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Bug.MainPage">
    <CollectionView>
        <CollectionView.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>A</x:String>
                <x:String>B</x:String>
            </x:Array>
        </CollectionView.ItemsSource>
        <CollectionView.Header>
            <OnPlatform x:TypeArguments="View">
                <On Platform="Android">
                    <Label Text="Android" />
                </On>
                <On Platform="WinUI">
                    <Label Text="WinUI" />
                </On>
            </OnPlatform>
        </CollectionView.Header>
    </CollectionView>
    </ContentPage>

Link to public reproduction project repository

No response

Version with bug

9.0.0-rc.1.24453.9

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

No.

Relevant log output

No response

Zhanglirong-Winnie commented 1 month ago

This issue has been verified using Visual Studio 17.12.0 Preview 2.1(9.0.0-rc.1.24453.9 & 8.0.91 & 8.0.82). Can repro this issue on windows and android platforms.