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

Fixed Header and Footer template is not visible in CollectionView #26844

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected virtual void UpdateHeader()
_currentHeader = null;
}

var header = ItemsView.Header;
var header = ItemsView.Header ?? ItemsView.HeaderTemplate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we just left this as var header = ItemsView.Header

And then just deleted the
case null:

would that do the same thing?

We might still want it to fall through to the default case

That way it will set both Header properties on the ListViewBase to null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine as is but I would change this to be a boolean, HasHeader and change switch statement. for example. ON the null I would also would make sure we clear the ListViewBase.HeaderTemplate just in case

This comment was marked as outdated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous comment was wrong :)

Having the switch here is fine, but the default case still having to check the header is a bit redundant? I would think it should just be a case DataTemplate headerTemplate:

And then we would not need the null and default would be the null where we null out both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need the null if you clear the template and we want to clear on the native side too.


switch (header)
{
Expand All @@ -133,7 +133,7 @@ protected virtual void UpdateHeader()
if (headerTemplate != null)
{
ListViewBase.HeaderTemplate = ItemsViewTemplate;
ListViewBase.Header = new ItemTemplateContext(headerTemplate, header, Element);
ListViewBase.Header = new ItemTemplateContext(headerTemplate, header, Element, mauiContext: MauiContext);
}
else
{
Expand All @@ -157,7 +157,7 @@ protected virtual void UpdateFooter()
_currentFooter = null;
}

var footer = ItemsView.Footer;
var footer = ItemsView.Footer ?? ItemsView.FooterTemplate;

switch (footer)
{
Expand All @@ -182,7 +182,7 @@ protected virtual void UpdateFooter()
if (footerTemplate != null)
{
ListViewBase.FooterTemplate = ItemsViewTemplate;
ListViewBase.Footer = new ItemTemplateContext(footerTemplate, footer, Element);
ListViewBase.Footer = new ItemTemplateContext(footerTemplate, footer, Element, mauiContext: MauiContext);
}
else
{
Expand Down
3 changes: 0 additions & 3 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue8761.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiCollectionViewFooterBug"
x:Class="Maui.Controls.Sample.Issues.Issue8761">

<CollectionView ItemsSource="{Binding Items}">
<CollectionView.HeaderTemplate>
<DataTemplate>
Expand Down Expand Up @@ -33,5 +31,4 @@
</DataTemplate>
</CollectionView.FooterTemplate>
</CollectionView>

</ContentPage>
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if ANDROID
// https://github.com/dotnet/maui/issues/22892
using NUnit.Framework;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -25,5 +23,4 @@ public void CollectionViewHeaderTemplateAndFooterTemplateDontWork()
App.WaitForElement("FooterLabel");
}
}
}
#endif
}
Loading