-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fixed - Using CollectionView.EmptyView results in an Exception on Windows #28367
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
Merged
PureWeen
merged 10 commits into
dotnet:inflight/current
from
KarthikRajaKalaimani:fix-28212
Mar 18, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
488ef98
Fixed Using CollectionView.EmptyView results in an Exception on Windows
KarthikRajaKalaimani 769d214
Test case written and fix slightly modified
KarthikRajaKalaimani 7000cb2
Test case modified
KarthikRajaKalaimani bb19698
Snap added for android and iOS
KarthikRajaKalaimani d19d99b
Test case modified
KarthikRajaKalaimani 36ab064
Merge branch 'fix-28212' of https://github.com/KarthikRajaKalaimani/m…
KarthikRajaKalaimani 5e72ed7
snap removed
KarthikRajaKalaimani 99db508
Test case modified
KarthikRajaKalaimani 79f47c8
Removed curly braces
KarthikRajaKalaimani 7f3e476
Test case modified
KarthikRajaKalaimani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.ObjectModel; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 28212, "Using CollectionView.EmptyView results in an Exception on Windows", PlatformAffected.WinPhone)] | ||
| public class Issue28212 : NavigationPage | ||
| { | ||
| Issue28212_Page1 _issue28212_Page1; | ||
| public Issue28212() | ||
| { | ||
| _issue28212_Page1 = new Issue28212_Page1(); | ||
| this.PushAsync(_issue28212_Page1); | ||
| } | ||
| } | ||
|
|
||
| public class Issue28212_Page1 : ContentPage | ||
| { | ||
| VerticalStackLayout verticalStackLayout; | ||
| Issue28212_Page2 _issue28212_Page2; | ||
| Button button; | ||
| public Issue28212_Page1() | ||
| { | ||
| _issue28212_Page2 = new Issue28212_Page2(); | ||
| button = new Button(); | ||
| button.Text = "Click to Navigate"; | ||
| button.AutomationId = "Button"; | ||
| button.Clicked += Button_Clicked; | ||
| button.HeightRequest = 100; | ||
| verticalStackLayout = new VerticalStackLayout(); | ||
| verticalStackLayout.Children.Add(button); | ||
| this.Content = verticalStackLayout; | ||
| } | ||
|
|
||
| private void Button_Clicked(object sender, EventArgs e) | ||
| { | ||
| Navigation.PushAsync(_issue28212_Page2); | ||
| } | ||
| } | ||
|
|
||
| public class Issue28212_Page2 : ContentPage | ||
| { | ||
| public ObservableCollection<string> Items { get; } = []; | ||
| VerticalStackLayout verticalStackLayout; | ||
| Button backButton; | ||
| Button addButton; | ||
| CollectionView _collectionView; | ||
| Label emptyLabel; | ||
| public Issue28212_Page2() | ||
| { | ||
| _collectionView = new CollectionView(); | ||
| _collectionView.ItemsSource = Items; | ||
| emptyLabel = new Label(); | ||
| emptyLabel.Text = "Empty"; | ||
| _collectionView.EmptyView = emptyLabel; | ||
| addButton = new Button(); | ||
| addButton.Text = "Add"; | ||
| addButton.Clicked += Button_Clicked; | ||
| backButton = new Button(); | ||
| backButton.Text = "Back"; | ||
| backButton.Clicked += BackButton_Clicked; | ||
| backButton.AutomationId = "BackButton"; | ||
| verticalStackLayout = new VerticalStackLayout(); | ||
| verticalStackLayout.Children.Add(addButton); | ||
| verticalStackLayout.Children.Add(backButton); | ||
| verticalStackLayout.Children.Add(_collectionView); | ||
| this.Content = verticalStackLayout; | ||
| } | ||
|
|
||
| private void BackButton_Clicked(object sender, EventArgs e) | ||
| { | ||
| Navigation.PopAsync(); | ||
| } | ||
|
|
||
| private void Button_Clicked(object sender, EventArgs e) | ||
| { | ||
| Items.Add("Item " + (Items.Count + 1)); | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28212.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue28212 : _IssuesUITest | ||
| { | ||
| public Issue28212(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Using CollectionView.EmptyView results in an Exception on Windows"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void Issue28212_CollectionView() | ||
| { | ||
| App.WaitForElement("Button"); | ||
| App.Click("Button"); | ||
| App.WaitForElement("Add"); | ||
| App.Click("Add"); | ||
| App.WaitForElement("Item 1"); | ||
| App.Click("BackButton"); | ||
| App.WaitForElement("Button"); | ||
| App.Click("Button"); | ||
| App.WaitForElement("Item 1"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The syntax '[]' is not a valid way to initialize an ObservableCollection in C#. Replace it with 'new ObservableCollection();' to correctly instantiate the collection.