Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectionView Header & Footer not showing #14557

Closed
sesitosvdx opened this issue Apr 13, 2023 · 39 comments · Fixed by #16870
Closed

CollectionView Header & Footer not showing #14557

sesitosvdx opened this issue Apr 13, 2023 · 39 comments · Fixed by #16870
Assignees
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView delighter fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@sesitosvdx
Copy link

sesitosvdx commented Apr 13, 2023

Description

When trying to add any content inside a Header/Footer to a CollectionView, it is not being displayed. Only happens in Windows. Works well for Android and iOS.

Steps to Reproduce

Create new project
Add CollectionView with a ItemsSource
Add a Header/Footer to the CollectionView

    <CollectionView x:Name="collectionview"
                    ItemsSource="{Binding Monkeys}">            
        <CollectionView.Header>
        <VerticalStackLayout BackgroundColor="LightGray">
                <Label Margin="10,0,0,0"
                       Text="Monkeys"
                       FontSize="12"
                       FontAttributes="Bold" />
            </VerticalStackLayout>
        </CollectionView.Header>
        <CollectionView.Footer>
            <VerticalStackLayout BackgroundColor="LightGray">
                <Label Margin="10,0,0,0"
                       Text="Friends of Xamarin Monkey"
                       FontSize="12"
                       FontAttributes="Bold" />
            </VerticalStackLayout>
        </CollectionView.Footer>
        <CollectionView.ItemTemplate>
            <DataTemplate>
                ...
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>

image

Link to public reproduction project repository

https://github.com/sesitosvdx/CollectionViewHeaderFooterWindowsBug

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows10.0.19041.0

Did you find any workaround?

#14557 (comment)

Relevant log output

No response

@sesitosvdx sesitosvdx added the t/bug Something isn't working label Apr 13, 2023
@drasticactions
Copy link
Contributor

I can reproduce this.

スクリーンショット 2023-04-13 17 26 51

If you look at the raw Live Visual Tree for WinUI (Not MAUIs, but the WinUI Controls that MAUI creates) you can see the header and footer for the view. There's nothing rendered in them. If I hack them with Live Property Explorer, you can force them to appear, but whatever is there when compiled doesn't work.

@drasticactions drasticactions added s/verified Verified / Reproducible Issue ready for Engineering Triage platform/windows 🪟 area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Apr 13, 2023
@HobDev
Copy link

HobDev commented Apr 15, 2023

facing same issue on windows after updating visual studio to Version 17.5.4

@drasticactions drasticactions changed the title CollectionView Header & Footer not showing in Windows CollectionView Header & Footer not showing Apr 17, 2023
@drasticactions
Copy link
Contributor

#14603

This seems to be happening on Android too. Checking this sample on Android, I believe something similar is happening there.

@Strypper
Copy link

Mine happing too
Visual studio I'm using also 17.5.4

@jsuarezruiz jsuarezruiz added this to the Backlog milestone Apr 17, 2023
@pwisk
Copy link

pwisk commented Apr 19, 2023

The same is happening in my project on Windows. On Android view is generated but events are firing incorrectly when I have sublist with CollectionView.
I suspect it's caused by Windows App SDK 1.3.
I use Visual Studio 17.6.0 Preview 2.0. Preview 3.0 i broken for .NET MAUI.

@alizorlu
Copy link

Hello to everyone,

I ran into the same problem a while ago. The problem is, when we assign a value to the "EmptyView" property as a template, the header template in the collectionview gets corrupted. You can try it in Android environment.

Example;
emptyview_code

With (Set emptyview property)
emptyview_1

Without(not set emptyview property)
emptyview_2

@nephesh
Copy link

nephesh commented May 3, 2023

I have the same issue only in Windows. I'm using Visual Studio 17.5.5, and it was working on the previous VS version 17.5.2.

@williambohrmann3
Copy link

Able to repro missing header on Windows with VS 17.5.4. Same control displays header just fine when deploying to Android, iOS, and MacCatalyst.

@dimustriz
Copy link

As a workaround, it is possible to subscribe to Scrolled event of a CollectionView and then show/hide separately placed header/fooler views based on a scroll direction.

Though I am looking forward the issue fix. :-)

@jsuarezruiz
Copy link
Contributor

Tried https://github.com/sesitosvdx/CollectionViewHeaderFooterWindowsBug on main branch and cannot reproduce the issue on Windows.

issue-14557
Could someone attach a sample where reproduce the issue? @drasticactions Maybe I am missing something?

@williambohrmann3
Copy link

@jsuarezruiz here is a pretty simple sample; notice the header and footer is visible on Android but not visible on Windows. On VS 17.5.4
header_footer_android
ojuBVsKIxI

@samhouts samhouts added the p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint label May 10, 2023
@githubgoucho
Copy link

githubgoucho commented May 12, 2023

2.3k issues + 1;
My Testbed: https://github.com/githubgoucho/CollectionViewTest
android
Win10UI

@AathifMahir
Copy link

Noticing Same Issue in Windows, Not Sure about Other Platforms. Therefore, Going with Custom Header and Footer for Now

@drossoft
Copy link

Same issue after updating VS to version 17.6.0

@samhouts samhouts modified the milestones: Backlog, .NET 8 May 24, 2023
@SteveMaier-IRT
Copy link

Same issue.

@ne0rrmatrix
Copy link

I am having the same issue. If anyone has a work around I would love to know about it. I use a header for when loading data and I am unable to use it on windows atm. It works fine on android and ios.

@kunyli kunyli self-assigned this Jun 7, 2023
@GerhardMauerberger
Copy link

Same issue on VS 17.6.2 on Windows. No problem on Android.

@NunoBem
Copy link

NunoBem commented Jun 21, 2023

Is this only gonna be fixed in .NET 8? Have a production app that needs this...

@dimustriz
Copy link

As a workaround it is possible to use ItemTemplateSelector and move Header/Footer to the first/last element.

@samhouts
Copy link
Member

Still a problem as of 8.0-preview 6.

@enisn
Copy link

enisn commented Jul 18, 2023

Still continues on Windows

@samhouts
Copy link
Member

It might be helpful to know that it does show on Windows if you use a text value. It fails when you try to use a View or a DataTemplate (using HeaderTemplate). So it looks like our ViewTemplate or the ViewToHandler converter is not working in this scenario.

@MegaEgorik
Copy link

To make the CollectionView.Header work on Windows, you need to write this code in App.xaml.cs:
CollectionViewHandler.Mapper.AppendToMapping("Header", (handler, _) => _.AddLogicalChild(handler.PlatformView.Header as Element));

@MegaEgorik
Copy link

MegaEgorik commented Jul 26, 2023

I thought the code above only works for header, but it works for footer too:

CollectionViewHandler.Mapper.AppendToMapping("HeaderAndFooterFix", (_, collectionView) =>
{
    collectionView.AddLogicalChild(collectionView.Header as Element);
    collectionView.AddLogicalChild(collectionView.Footer as Element);
});

@Blinchik91
Copy link

same on android, collectionview header not visible, iOS is fine

@CarlosGod
Copy link

I write this code in my app.xaml.cs,but it still not work.Can u show me code

@ne0rrmatrix
Copy link

ne0rrmatrix commented Aug 3, 2023

I write this code in my app.xaml.cs,but it still not work.Can u show me code

You may have copied it into App.xaml.cs in the main directory. You need to copy it into the Windows devices specific area in /Platforms/Windows/App.xaml.cs.

Sample app with fix to help you. Look in Platforms/Windows/App.xaml.cs
https://github.com/ne0rrmatrix/HeaderSample

Or just copy past this into constructor for App.xaml.cs

 // Below is code to make Headers work for CollectionView for windows. Also works for footers.
        // All credit is due to MegaEgorik https://github.com/dotnet/maui/issues/14557#issuecomment-1651575327
        CollectionViewHandler.Mapper.AppendToMapping("HeaderAndFooterFix", (_, collectionView) =>
        {
            collectionView.AddLogicalChild(collectionView.Header as Element);
            collectionView.AddLogicalChild(collectionView.Footer as Element);
        });

@WithoutAnAce
Copy link

Hmm, I tried @MegaEgorik's fix and it worked for my header but not my footer. Can work around it for now, but interesting nonetheless

@MegaEgorik
Copy link

Hmm, I tried @MegaEgorik's fix and it worked for my header but not my footer. Can work around it for now, but interesting nonetheless

Maybe you just didn't set a HeightRequest for the footer and that's why it's not showing up.
This code works fine for me and all headers and footers for each CollectionView are displayed.

@WithoutAnAce
Copy link

WithoutAnAce commented Aug 8, 2023

Hmm, I tried @MegaEgorik's fix and it worked for my header but not my footer. Can work around it for now, but interesting nonetheless

Maybe you just didn't set a HeightRequest for the footer and that's why it's not showing up. This code works fine for me and all headers and footers for each CollectionView are displayed.

Entirely possible! I'm a relatively new dev - would this be an OK place to ask where I'm going wrong here implementing this workaround?

...
        <CollectionView
            Margin="1"
            ItemsSource="{Binding AgendaItems}"
            VerticalScrollBarVisibility="Always">
            <CollectionView.Header>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition x:Name="NameColumn" Width="*" />
                        <ColumnDefinition x:Name="LocationColumn" Width="*" />
                        <ColumnDefinition x:Name="StartTimeColumn" Width="*" />
                        <ColumnDefinition x:Name="EndTimeColumn" Width="*" />
                        <ColumnDefinition x:Name="RecurrenceColumn" Width="*" />
                    </Grid.ColumnDefinitions>
                    <Label Grid.Column="0" Text="Event Name" />
                    <Label Grid.Column="1" Text="Location" />
                    <Label Grid.Column="2" Text="StartTime" />
                    <Label Grid.Column="3" Text="EndTime" />
                    <Label Grid.Column="4" Text="Recurs?" />
                </Grid>
            </CollectionView.Header>
            <CollectionView.Footer>
                <Label Text="TestMessage" HeightRequest="24" MinimumHeightRequest="16"/>
            </CollectionView.Footer>
...

but this only shows the header, not the footer
image

@MegaEgorik
Copy link

...
        <CollectionView
            Margin="1"
            ItemsSource="{Binding AgendaItems}"
            VerticalScrollBarVisibility="Always">
            <CollectionView.Header>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition x:Name="NameColumn" Width="*" />
                        <ColumnDefinition x:Name="LocationColumn" Width="*" />
                        <ColumnDefinition x:Name="StartTimeColumn" Width="*" />
                        <ColumnDefinition x:Name="EndTimeColumn" Width="*" />
                        <ColumnDefinition x:Name="RecurrenceColumn" Width="*" />
                    </Grid.ColumnDefinitions>
                    <Label Grid.Column="0" Text="Event Name" />
                    <Label Grid.Column="1" Text="Location" />
                    <Label Grid.Column="2" Text="StartTime" />
                    <Label Grid.Column="3" Text="EndTime" />
                    <Label Grid.Column="4" Text="Recurs?" />
                </Grid>
            </CollectionView.Header>
            <CollectionView.Footer>
                <Label Text="TestMessage" HeightRequest="24" MinimumHeightRequest="16"/>
            </CollectionView.Footer>
...

but this only shows the header, not the footer image

Try updating .NET MAUI to the latest version.
I have the latest version and the fix works fine.
image
image
image

@WithoutAnAce
Copy link

@MegaEgorik Thank you for the assistance. Working forwards from your example, I was able to figure out that the footer wasn't displaying because I had added an Init() event listener listening to the Loaded event of the view, and in that event listener I was updating AgendaItems without being on the main thread. My init method now looks like this:

        public override void Init()
        {
            Application.Current?.Dispatcher.Dispatch(()=>
            AgendaItems = new ObservableCollection<IAgendaItem>()
            );
            _timeService.StartTimer();
            ResetInputFields();
            base.Init();
        }

and your workaround in App.xaml is working correctly (though I will note for MSFT's sake that it is still a workaround, and the underlying issue is not fixed) Thank you so much!

@samhouts
Copy link
Member

samhouts commented Aug 8, 2023

Woohoo! Thanks for the team effort finding workarounds, friends! I assure you this is still a top priority to fix!

@MegaEgorik
Copy link

I also made workaround for this issue on Windows -> #12499

@xx7Ahmed7xx
Copy link

I thought the code above only works for header, but it works for footer too:

CollectionViewHandler.Mapper.AppendToMapping("HeaderAndFooterFix", (_, collectionView) =>
{
    collectionView.AddLogicalChild(collectionView.Header as Element);
    collectionView.AddLogicalChild(collectionView.Footer as Element);
});

This code works, I put it in the main App.xaml.cs (Under App.xaml) and immediately saw the header.
I'm super sad that MAUI has alot of design issues although it is kinda more than 2 years old ..

@drossoft
Copy link

The solution proposed by @MegaEgorik works, but in my case, the footer is only shown the second time you navigate to the page, the first time only the header appears.

Also, the first time you navigate to the page, neither the header nor the footer have the BindingContext set, I had to set it in the OnAppearing method of the page.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 6, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! label Oct 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView delighter fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.