-
Notifications
You must be signed in to change notification settings - Fork 1.9k
CollectionView, the footer moves to the bottom of the page when the empty view or empty view template is enabled #24997
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
Changes from all commits
2240f52
5ea08bc
5c03cfc
f35e50b
b487c7b
7fd7490
1fcd471
ee19c3a
21310ba
ada6af8
e7d296b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue24966" | ||
| xmlns:cv1="clr-namespace:Maui.Controls.Sample" | ||
| xmlns:local="clr-namespace:Maui.Controls.Sample.Issues" | ||
| x:Name="ThisMainPage" | ||
| Title="Main Page"> | ||
|
|
||
| <Grid RowDefinitions="Auto,*"> | ||
|
|
||
| <HorizontalStackLayout | ||
| Grid.Row="0" | ||
| Padding="20" | ||
| HorizontalOptions="Center" | ||
| Spacing="20"> | ||
| <Button Command="{Binding AddCommand}" Text="Add item" AutomationId="AddButton" /> | ||
| <Button Command="{Binding RemoveCommand}" Text="Remove item" AutomationId="RemoveButton" /> | ||
| </HorizontalStackLayout> | ||
|
|
||
| <cv1:CollectionView1 Grid.Row="1" ItemsSource="{Binding ItemList}"> | ||
|
|
||
| <cv1:CollectionView1.HeaderTemplate> | ||
| <DataTemplate> | ||
| <Label | ||
| Padding="10" | ||
| FontAttributes="Bold" | ||
| FontSize="Large" | ||
| Text="Cities" /> | ||
| </DataTemplate> | ||
| </cv1:CollectionView1.HeaderTemplate> | ||
|
|
||
| <cv1:CollectionView1.ItemTemplate> | ||
| <DataTemplate> | ||
| <Label Padding="20,5,5,5" Text="{Binding .}" /> | ||
| </DataTemplate> | ||
| </cv1:CollectionView1.ItemTemplate> | ||
|
|
||
| <cv1:CollectionView1.EmptyViewTemplate> | ||
| <DataTemplate> | ||
| <Label Padding="20,5,5,5" Text="Empty" /> | ||
| </DataTemplate> | ||
| </cv1:CollectionView1.EmptyViewTemplate> | ||
|
|
||
| <cv1:CollectionView1.FooterTemplate> | ||
| <DataTemplate> | ||
| <Label | ||
| Padding="10" | ||
| FontAttributes="Bold" | ||
| FontSize="Large" | ||
| Text="Hello world !!!" /> | ||
| </DataTemplate> | ||
| </cv1:CollectionView1.FooterTemplate> | ||
|
|
||
| </cv1:CollectionView1> | ||
|
|
||
| </Grid> | ||
| </ContentPage> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.ObjectModel; | ||
| using System.ComponentModel; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Windows.Input; | ||
| using System.Collections.Specialized; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues | ||
| { | ||
| [XamlCompilation(XamlCompilationOptions.Compile)] | ||
| [Issue(IssueTracker.Github, 24966, "CollectionView, the footer moves to the bottom of the page when the empty view or empty view template is enabled")] | ||
| public partial class Issue24966 | ||
| { | ||
| public Issue24966() | ||
| { | ||
| InitializeComponent(); | ||
| BindingContext = new Issue24966ViewModel(); | ||
| } | ||
| } | ||
| internal class Issue24966ViewModel | ||
| { | ||
| // Define a static list of cities to add to the collection | ||
| private List<string> _staticCities = new() | ||
| { | ||
| "Paris", | ||
| "New York", | ||
| "Tokyo", | ||
| "Berlin", | ||
| "Madrid", | ||
| "London" | ||
| }; | ||
|
|
||
| private int _currentIndex = 0; | ||
|
|
||
| public ObservableCollection<string> ItemList { get; set; } | ||
|
|
||
| public ICommand AddCommand => new Command(Add); | ||
| public ICommand RemoveCommand => new Command(Remove); | ||
|
|
||
| public Issue24966ViewModel() | ||
| { | ||
| // Initialize the ItemList | ||
| ItemList = new ObservableCollection<string>(); | ||
| } | ||
|
|
||
| private void Add() | ||
| { | ||
| // Add the next city from the static list | ||
| if (_currentIndex < _staticCities.Count) | ||
| { | ||
| ItemList.Add(_staticCities[_currentIndex]); | ||
| _currentIndex++; | ||
| } | ||
| else | ||
| { | ||
| // Optionally reset the index or handle the end of the list as needed | ||
| _currentIndex = 0; // Resetting to allow cycling through the list again | ||
| } | ||
| } | ||
|
|
||
| private void Remove() | ||
| { | ||
| // Remove the last item in the list if any exist | ||
| if (ItemList.Count > 0) | ||
| { | ||
| ItemList.RemoveAt(ItemList.Count - 1); | ||
| // Decrement the index to ensure the correct city is added next time | ||
| _currentIndex = Math.Max(0, _currentIndex - 1); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #if !MACCATALYST && !WINDOWS | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues | ||
| { | ||
| internal class Issue24966 : _IssuesUITest | ||
| { | ||
| public Issue24966(TestDevice device) : base(device) { } | ||
|
|
||
| public override string Issue => "CollectionView, the footer moves to the bottom of the page when the empty view or empty view template is enabled"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void CollectionViewFooterMovestoBottomWithEmptyvieworEmptyviewTemplate() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test is failing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since updating to .NET 9 and enabling A separate issue has been created to track progress: #25606, |
||
| { | ||
| App.WaitForElement("AddButton"); | ||
| App.Tap("AddButton"); | ||
| App.Tap("AddButton"); | ||
| App.Tap("RemoveButton"); | ||
| App.Tap("RemoveButton"); | ||
| // Here we check for dynamic Emptyview and Footer proper proper alignment in view it should not be at the bottom of screen. | ||
| VerifyScreenshot(); | ||
rmarinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| #endif | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vignesh-SF3580 this regressed when we don t have a layout as an empty view. I m created issue #26508 to track this. Do you have any ideas here? seems the height of a button is always 0 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rmarinho , The issue occurs because the WrapperView for the button is being set during the rendering phase in the SetupContainer method. However, when the DetermineEmptyViewFrame method is called to measure the button, the SizeThatFitsWrapper logic is triggered. At this point, the WrapperView has no subviews, resulting in the default size (0, 0) being returned. This is due to the fact that the measurement depends on the subview hierarchy, which is not yet fully initialized during this phase.
The PR created by you PR #26513 effectively addresses this scenario.