This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Notify child added to CollectionView * Automate the test * Fixed merge problem Co-authored-by: E.Z. Hart <hartez@gmail.com>
- Loading branch information
1 parent
5eb6e1e
commit 85f7e4f
Showing
3 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue10454.cs
This file contains 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,105 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
#if UITEST | ||
using Xamarin.Forms.Core.UITests; | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
#if UITEST | ||
[Category(UITestCategories.CollectionView)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 10454, "CollectionView ChildAdded", PlatformAffected.All)] | ||
public class Issue10454 : TestContentPage | ||
{ | ||
const string Success = "Success"; | ||
|
||
protected override void Init() | ||
{ | ||
Title = "Issue 10454"; | ||
|
||
BindingContext = new Issue10454ViewModel(); | ||
|
||
var layout = new StackLayout(); | ||
|
||
var collectionView = new CollectionView(); | ||
collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Items"); | ||
|
||
collectionView.ItemTemplate = new DataTemplate(() => | ||
{ | ||
var template = new DataTemplate(); | ||
var content = new Grid | ||
{ | ||
BackgroundColor = Color.LightGray | ||
}; | ||
var label = new Label(); | ||
label.SetBinding(Label.TextProperty, "."); | ||
content.Children.Add(label); | ||
return content; | ||
}); | ||
|
||
var labelInfo = new Label | ||
{ | ||
FontSize = 18 | ||
}; | ||
|
||
var successLabel = new Label(); | ||
|
||
layout.Children.Add(labelInfo); | ||
layout.Children.Add(successLabel); | ||
layout.Children.Add(collectionView); | ||
|
||
Content = layout; | ||
|
||
collectionView.ChildAdded += (sender, args) => | ||
{ | ||
labelInfo.Text = $"ChildAdded {args.Element}"; | ||
Console.WriteLine(labelInfo.Text); | ||
successLabel.Text = Success; | ||
}; | ||
|
||
collectionView.ChildRemoved += (sender, args) => | ||
{ | ||
labelInfo.Text = $"ChildRemoved {args.Element}"; | ||
Console.WriteLine(labelInfo.Text); | ||
}; | ||
} | ||
|
||
#if UITEST | ||
[Test] | ||
public void ChildAddedShouldFire() | ||
{ | ||
RunningApp.WaitForElement(Success); | ||
} | ||
#endif | ||
} | ||
|
||
[Preserve(AllMembers = true)] | ||
public class Issue10454ViewModel : BindableObject | ||
{ | ||
public Issue10454ViewModel() | ||
{ | ||
LoadItems(); | ||
} | ||
|
||
public ObservableCollection<string> Items { get; set; } | ||
|
||
void LoadItems() | ||
{ | ||
Items = new ObservableCollection<string>(); | ||
|
||
for (int i = 0; i < 100; i++) | ||
{ | ||
Items.Add($"Item {i+1}"); | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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