|
| 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 | +} |
0 commit comments