Skip to content

OnPlatform does not work in Header of CollectionView #25124

Open
@suugbut

Description

@suugbut

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions