Skip to content

Commit 298491f

Browse files
KarthikRajaKalaimaniPureWeen
authored andcommitted
Fixed - Using CollectionView.EmptyView results in an Exception on Windows (#28367)
* Fixed Using CollectionView.EmptyView results in an Exception on Windows * Test case written and fix slightly modified * Test case modified * Snap added for android and iOS * Test case modified * snap removed * Test case modified * Removed curly braces * Test case modified
1 parent aa35b01 commit 298491f

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ protected override void DisconnectHandler(ListViewBase platformView)
5858
{
5959
VirtualView.ScrollToRequested -= ScrollToRequested;
6060
CleanUpCollectionViewSource(platformView);
61+
_formsEmptyView?.Handler?.DisconnectHandler();
6162
base.DisconnectHandler(platformView);
6263
}
6364

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Maui.Controls.Sample.Issues;
9+
10+
[Issue(IssueTracker.Github, 28212, "Using CollectionView.EmptyView results in an Exception on Windows", PlatformAffected.WinPhone)]
11+
public class Issue28212 : NavigationPage
12+
{
13+
Issue28212_Page1 _issue28212_Page1;
14+
public Issue28212()
15+
{
16+
_issue28212_Page1 = new Issue28212_Page1();
17+
this.PushAsync(_issue28212_Page1);
18+
}
19+
}
20+
21+
public class Issue28212_Page1 : ContentPage
22+
{
23+
VerticalStackLayout verticalStackLayout;
24+
Issue28212_Page2 _issue28212_Page2;
25+
Button button;
26+
public Issue28212_Page1()
27+
{
28+
_issue28212_Page2 = new Issue28212_Page2();
29+
button = new Button();
30+
button.Text = "Click to Navigate";
31+
button.AutomationId = "Button";
32+
button.Clicked += Button_Clicked;
33+
button.HeightRequest = 100;
34+
verticalStackLayout = new VerticalStackLayout();
35+
verticalStackLayout.Children.Add(button);
36+
this.Content = verticalStackLayout;
37+
}
38+
39+
private void Button_Clicked(object sender, EventArgs e)
40+
{
41+
Navigation.PushAsync(_issue28212_Page2);
42+
}
43+
}
44+
45+
public class Issue28212_Page2 : ContentPage
46+
{
47+
public ObservableCollection<string> Items { get; } = [];
48+
VerticalStackLayout verticalStackLayout;
49+
Button backButton;
50+
Button addButton;
51+
CollectionView _collectionView;
52+
Label emptyLabel;
53+
public Issue28212_Page2()
54+
{
55+
_collectionView = new CollectionView();
56+
_collectionView.ItemsSource = Items;
57+
emptyLabel = new Label();
58+
emptyLabel.Text = "Empty";
59+
_collectionView.EmptyView = emptyLabel;
60+
addButton = new Button();
61+
addButton.Text = "Add";
62+
addButton.Clicked += Button_Clicked;
63+
backButton = new Button();
64+
backButton.Text = "Back";
65+
backButton.Clicked += BackButton_Clicked;
66+
backButton.AutomationId = "BackButton";
67+
verticalStackLayout = new VerticalStackLayout();
68+
verticalStackLayout.Children.Add(addButton);
69+
verticalStackLayout.Children.Add(backButton);
70+
verticalStackLayout.Children.Add(_collectionView);
71+
this.Content = verticalStackLayout;
72+
}
73+
74+
private void BackButton_Clicked(object sender, EventArgs e)
75+
{
76+
Navigation.PopAsync();
77+
}
78+
79+
private void Button_Clicked(object sender, EventArgs e)
80+
{
81+
Items.Add("Item " + (Items.Count + 1));
82+
}
83+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue28212 : _IssuesUITest
8+
{
9+
public Issue28212(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "Using CollectionView.EmptyView results in an Exception on Windows";
14+
15+
[Test]
16+
[Category(UITestCategories.CollectionView)]
17+
public void Issue28212_CollectionView()
18+
{
19+
App.WaitForElement("Button");
20+
App.Click("Button");
21+
App.WaitForElement("Add");
22+
App.Click("Add");
23+
App.WaitForElement("Item 1");
24+
App.Click("BackButton");
25+
App.WaitForElement("Button");
26+
App.Click("Button");
27+
App.WaitForElement("Item 1");
28+
}
29+
}

0 commit comments

Comments
 (0)