diff --git a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/CollectionViewFeaturePage.xaml.cs b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/CollectionViewFeaturePage.xaml.cs index 45f9cc5f3f69..ec40e39aec40 100644 --- a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/CollectionViewFeaturePage.xaml.cs +++ b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/CollectionViewFeaturePage.xaml.cs @@ -47,7 +47,7 @@ private async void OnSelectionButtonClicked(object sender, EventArgs e) await Navigation.PushAsync(new CollectionViewSelectionPage()); } - + private async void OnItemsSourceButtonClicked(object sender, EventArgs e) { await Navigation.PushAsync(new CollectionViewItemsSourcePage()); diff --git a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/CollectionViewViewModel.cs b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/CollectionViewViewModel.cs index 10e0e5db145f..4f820650a33c 100644 --- a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/CollectionViewViewModel.cs +++ b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/CollectionViewViewModel.cs @@ -1,95 +1,95 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; +using System.Windows.Input; +using Maui.Controls.Sample.CollectionViewGalleries; using Microsoft.Maui.Controls; using Microsoft.Maui.Graphics; -using Maui.Controls.Sample.CollectionViewGalleries; -using System.Windows.Input; -using System.Collections.Specialized; namespace Maui.Controls.Sample; public class Grouping : ObservableCollection { - public TKey Key { get; } + public TKey Key { get; } - public Grouping(TKey key, IEnumerable items) : base(items) - { - Key = key; - } + public Grouping(TKey key, IEnumerable items) : base(items) + { + Key = key; + } } public enum ItemsSourceType { - None, - ObservableCollectionT, - ObservableCollectionT2, - ObservableCollectionT3, - ObservableCollection25T, - ObservableCollection5T, - GroupedListT, - EmptyGroupedListT, - EmptyObservableCollectionT, - GroupedListT2, - GroupedListT3, - ObservableCollectionStringT, - ObservableCollectionModelT, - ListT, - ListModelT, - GroupedListStringT, - GroupedListModelT, - EmptyGroupedListModelT, - EmptyObservableCollectionModelT + None, + ObservableCollectionT, + ObservableCollectionT2, + ObservableCollectionT3, + ObservableCollection25T, + ObservableCollection5T, + GroupedListT, + EmptyGroupedListT, + EmptyObservableCollectionT, + GroupedListT2, + GroupedListT3, + ObservableCollectionStringT, + ObservableCollectionModelT, + ListT, + ListModelT, + GroupedListStringT, + GroupedListModelT, + EmptyGroupedListModelT, + EmptyObservableCollectionModelT } public class CollectionViewViewModel : INotifyPropertyChanged { private object _emptyView; - private object _header; - private object _footer; - private DataTemplate _emptyViewTemplate; - private DataTemplate _headerTemplate; - private DataTemplate _footerTemplate; - private DataTemplate _groupHeaderTemplate; - private DataTemplate _groupFooterTemplate; - private DataTemplate _itemTemplate; - private IItemsLayout _itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical); - private ItemsSourceType _itemsSourceType = ItemsSourceType.None; - private bool _isGrouped = false; - private bool _canReorderItems = false; - private bool _canMixGroups = false; - private bool _itemsSourceStringItems = true; - private ItemSizingStrategy _itemSizingStrategy; - private ItemsUpdatingScrollMode _itemsUpdatingScrollMode; - private ObservableCollection _observableCollection; - private ObservableCollection _observableCollection25; - private ObservableCollection _observableCollection5; - private ObservableCollection _emptyObservableCollection; - private List> _groupedList; - private List> _emptyGroupedList; - private ObservableCollection _observableCollection3; - private ObservableCollection _observableCollection2; - private List> _groupedList3; - private List> _groupedList2; - private ObservableCollection _observableCollectionString; - private ObservableCollection _observableCollectionModel; - private ObservableCollection _emptyObservableCollectionModel; - private List> _groupedListString; - private List> _groupedListModel; - private List> _emptyGroupedListModel; - private List _list; - private List _listModel; - private SelectionMode _selectionMode = SelectionMode.None; - private object _selectedItem; - private ObservableCollection _selectedItems = new ObservableCollection(); - private int _selectionChangedEventCount = 0; - private string _previousSelectionText; - private string _currentSelectionText; - private int fruitIndex = 0; - private int groupAIndex = 0; + private object _header; + private object _footer; + private DataTemplate _emptyViewTemplate; + private DataTemplate _headerTemplate; + private DataTemplate _footerTemplate; + private DataTemplate _groupHeaderTemplate; + private DataTemplate _groupFooterTemplate; + private DataTemplate _itemTemplate; + private IItemsLayout _itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical); + private ItemsSourceType _itemsSourceType = ItemsSourceType.None; + private bool _isGrouped = false; + private bool _canReorderItems = false; + private bool _canMixGroups = false; + private bool _itemsSourceStringItems = true; + private ItemSizingStrategy _itemSizingStrategy; + private ItemsUpdatingScrollMode _itemsUpdatingScrollMode; + private ObservableCollection _observableCollection; + private ObservableCollection _observableCollection25; + private ObservableCollection _observableCollection5; + private ObservableCollection _emptyObservableCollection; + private List> _groupedList; + private List> _emptyGroupedList; + private ObservableCollection _observableCollection3; + private ObservableCollection _observableCollection2; + private List> _groupedList3; + private List> _groupedList2; + private ObservableCollection _observableCollectionString; + private ObservableCollection _observableCollectionModel; + private ObservableCollection _emptyObservableCollectionModel; + private List> _groupedListString; + private List> _groupedListModel; + private List> _emptyGroupedListModel; + private List _list; + private List _listModel; + private SelectionMode _selectionMode = SelectionMode.None; + private object _selectedItem; + private ObservableCollection _selectedItems = new ObservableCollection(); + private int _selectionChangedEventCount = 0; + private string _previousSelectionText; + private string _currentSelectionText; + private int fruitIndex = 0; + private int groupAIndex = 0; private bool _isHeaderStringSelected; private bool _isFooterStringSelected; private bool _isHeaderGridSelected; @@ -143,291 +143,291 @@ public CollectionViewViewModel() SelectedItems.CollectionChanged += OnSelectedItemsChanged; } - public object EmptyView - { - get => _emptyView; - set { _emptyView = value; OnPropertyChanged(); } - } - - public object Header - { - get => _header; - set { _header = value; OnPropertyChanged(); } - } - - public object Footer - { - get => _footer; - set { _footer = value; OnPropertyChanged(); } - } - - public DataTemplate EmptyViewTemplate - { - get => _emptyViewTemplate; - set { _emptyViewTemplate = value; OnPropertyChanged(); } - } - - public DataTemplate HeaderTemplate - { - get => _headerTemplate; - set { _headerTemplate = value; OnPropertyChanged(); } - } - - public DataTemplate FooterTemplate - { - get => _footerTemplate; - set { _footerTemplate = value; OnPropertyChanged(); } - } - - public DataTemplate GroupHeaderTemplate - { - get => _groupHeaderTemplate; - set { _groupHeaderTemplate = value; OnPropertyChanged(); } - } - - public DataTemplate GroupFooterTemplate - { - get => _groupFooterTemplate; - set { _groupFooterTemplate = value; OnPropertyChanged(); } - } - - public DataTemplate ItemTemplate - { - get => _itemTemplate; - set { _itemTemplate = value; OnPropertyChanged(); } - } - - public IItemsLayout ItemsLayout - { - get => _itemsLayout; - set - { - if (_itemsLayout != value) - { - _itemsLayout = value; - OnPropertyChanged(); - } - } - } - - public ItemsSourceType ItemsSourceType - { - get => _itemsSourceType; - set - { - if (_itemsSourceType != value) - { - _itemsSourceType = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(ItemsSource)); - OnPropertyChanged(nameof(ShowAddRemoveButtons)); - SetItemTemplate(); - } - } - } - - public bool CanReorderItems - { - get => _canReorderItems; - set - { - if (_canReorderItems != value) - { - _canReorderItems = value; - OnPropertyChanged(); - } - } - } - public bool CanMixGroups - { - get => _canMixGroups; - set - { - if (_canMixGroups != value) - { - _canMixGroups = value; - OnPropertyChanged(); - } - } - } - - public bool IsGrouped - { - get => _isGrouped; - set - { - if (_isGrouped != value) - { - _isGrouped = value; - OnPropertyChanged(); - } - } - } - - public object ItemsSource - { - get - { - return ItemsSourceType switch - { - ItemsSourceType.ObservableCollectionT => _observableCollection, - ItemsSourceType.ObservableCollection25T => _observableCollection25, - ItemsSourceType.ObservableCollection5T => _observableCollection5, - ItemsSourceType.ObservableCollectionT3 => _observableCollection3, - ItemsSourceType.ObservableCollectionT2 => _observableCollection2, - ItemsSourceType.GroupedListT => _groupedList, - ItemsSourceType.GroupedListT2 => _groupedList2, - ItemsSourceType.EmptyGroupedListT => _emptyGroupedList, - ItemsSourceType.GroupedListT3 => _groupedList3, - ItemsSourceType.EmptyObservableCollectionT => _emptyObservableCollection, - ItemsSourceType.ObservableCollectionStringT => _observableCollectionString, - ItemsSourceType.ObservableCollectionModelT => _observableCollectionModel, - ItemsSourceType.GroupedListModelT => _groupedListModel, - ItemsSourceType.GroupedListStringT => _groupedListString, - ItemsSourceType.ListT => _list, - ItemsSourceType.ListModelT => _listModel, - ItemsSourceType.EmptyGroupedListModelT => _emptyGroupedListModel, - ItemsSourceType.EmptyObservableCollectionModelT => _emptyObservableCollectionModel, - ItemsSourceType.None => null, - _ => null - }; - } - } - - public ItemSizingStrategy ItemSizingStrategy - { - get => _itemSizingStrategy; - set - { - if (_itemSizingStrategy != value) - { - _itemSizingStrategy = value; - OnPropertyChanged(); - } - } - } - - public ItemsUpdatingScrollMode ItemsUpdatingScrollMode - { - get => _itemsUpdatingScrollMode; - set - { - if (_itemsUpdatingScrollMode != value) - { - _itemsUpdatingScrollMode = value; - OnPropertyChanged(); - } - } - } - - public SelectionMode SelectionMode - { - get => _selectionMode; - set - { - if (_selectionMode != value) - { - _selectionMode = value; - OnPropertyChanged(); - } - } - } - - public object SelectedItem - { - get => _selectedItem; - set - { - if (_selectedItem != value) - { - _selectedItem = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(SelectedItemText)); - OnPropertyChanged(nameof(SelectedItemsCount)); - } - } - } - - public ObservableCollection SelectedItems - { - get => _selectedItems; - set - { - if (_selectedItems != value) - { - _selectedItems = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(SelectedItemsCount)); - OnPropertyChanged(nameof(SelectedItemText)); - } - } - } - public int SelectedItemsCount - { - get - { - if (SelectionMode == SelectionMode.Single) - { - return SelectedItem != null ? 1 : 0; - } - else if (SelectionMode == SelectionMode.Multiple) - { - return SelectedItems?.Count ?? 0; - } - return 0; - - } - } - public string SelectedItemText - { - get - { - if (SelectionMode == SelectionMode.Single && SelectedItem is CollectionViewTestItem item) - { - return $"{item.Caption}"; - } - else if (SelectionMode == SelectionMode.Multiple && SelectedItems?.Count > 0) - { - var selectedCaptions = SelectedItems - .OfType() - .Select(i => i.Caption); - return string.Join(", ", selectedCaptions); - } - return "No items selected"; - } - } - - public int SelectionChangedEventCount - { - get => _selectionChangedEventCount; - set - { - _selectionChangedEventCount = value; - OnPropertyChanged(); - } - } - - public string PreviousSelectionText - { - get => _previousSelectionText; - set { _previousSelectionText = value; OnPropertyChanged(); } - } - - public string CurrentSelectionText - { - get => _currentSelectionText; - set { _currentSelectionText = value; OnPropertyChanged(); } - } - - public bool ItemsSourceStringItems - { - get => _itemsSourceStringItems; - set - { - _itemsSourceStringItems = value; - OnPropertyChanged(); - } - } + public object EmptyView + { + get => _emptyView; + set { _emptyView = value; OnPropertyChanged(); } + } + + public object Header + { + get => _header; + set { _header = value; OnPropertyChanged(); } + } + + public object Footer + { + get => _footer; + set { _footer = value; OnPropertyChanged(); } + } + + public DataTemplate EmptyViewTemplate + { + get => _emptyViewTemplate; + set { _emptyViewTemplate = value; OnPropertyChanged(); } + } + + public DataTemplate HeaderTemplate + { + get => _headerTemplate; + set { _headerTemplate = value; OnPropertyChanged(); } + } + + public DataTemplate FooterTemplate + { + get => _footerTemplate; + set { _footerTemplate = value; OnPropertyChanged(); } + } + + public DataTemplate GroupHeaderTemplate + { + get => _groupHeaderTemplate; + set { _groupHeaderTemplate = value; OnPropertyChanged(); } + } + + public DataTemplate GroupFooterTemplate + { + get => _groupFooterTemplate; + set { _groupFooterTemplate = value; OnPropertyChanged(); } + } + + public DataTemplate ItemTemplate + { + get => _itemTemplate; + set { _itemTemplate = value; OnPropertyChanged(); } + } + + public IItemsLayout ItemsLayout + { + get => _itemsLayout; + set + { + if (_itemsLayout != value) + { + _itemsLayout = value; + OnPropertyChanged(); + } + } + } + + public ItemsSourceType ItemsSourceType + { + get => _itemsSourceType; + set + { + if (_itemsSourceType != value) + { + _itemsSourceType = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(ItemsSource)); + OnPropertyChanged(nameof(ShowAddRemoveButtons)); + SetItemTemplate(); + } + } + } + + public bool CanReorderItems + { + get => _canReorderItems; + set + { + if (_canReorderItems != value) + { + _canReorderItems = value; + OnPropertyChanged(); + } + } + } + public bool CanMixGroups + { + get => _canMixGroups; + set + { + if (_canMixGroups != value) + { + _canMixGroups = value; + OnPropertyChanged(); + } + } + } + + public bool IsGrouped + { + get => _isGrouped; + set + { + if (_isGrouped != value) + { + _isGrouped = value; + OnPropertyChanged(); + } + } + } + + public object ItemsSource + { + get + { + return ItemsSourceType switch + { + ItemsSourceType.ObservableCollectionT => _observableCollection, + ItemsSourceType.ObservableCollection25T => _observableCollection25, + ItemsSourceType.ObservableCollection5T => _observableCollection5, + ItemsSourceType.ObservableCollectionT3 => _observableCollection3, + ItemsSourceType.ObservableCollectionT2 => _observableCollection2, + ItemsSourceType.GroupedListT => _groupedList, + ItemsSourceType.GroupedListT2 => _groupedList2, + ItemsSourceType.EmptyGroupedListT => _emptyGroupedList, + ItemsSourceType.GroupedListT3 => _groupedList3, + ItemsSourceType.EmptyObservableCollectionT => _emptyObservableCollection, + ItemsSourceType.ObservableCollectionStringT => _observableCollectionString, + ItemsSourceType.ObservableCollectionModelT => _observableCollectionModel, + ItemsSourceType.GroupedListModelT => _groupedListModel, + ItemsSourceType.GroupedListStringT => _groupedListString, + ItemsSourceType.ListT => _list, + ItemsSourceType.ListModelT => _listModel, + ItemsSourceType.EmptyGroupedListModelT => _emptyGroupedListModel, + ItemsSourceType.EmptyObservableCollectionModelT => _emptyObservableCollectionModel, + ItemsSourceType.None => null, + _ => null + }; + } + } + + public ItemSizingStrategy ItemSizingStrategy + { + get => _itemSizingStrategy; + set + { + if (_itemSizingStrategy != value) + { + _itemSizingStrategy = value; + OnPropertyChanged(); + } + } + } + + public ItemsUpdatingScrollMode ItemsUpdatingScrollMode + { + get => _itemsUpdatingScrollMode; + set + { + if (_itemsUpdatingScrollMode != value) + { + _itemsUpdatingScrollMode = value; + OnPropertyChanged(); + } + } + } + + public SelectionMode SelectionMode + { + get => _selectionMode; + set + { + if (_selectionMode != value) + { + _selectionMode = value; + OnPropertyChanged(); + } + } + } + + public object SelectedItem + { + get => _selectedItem; + set + { + if (_selectedItem != value) + { + _selectedItem = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(SelectedItemText)); + OnPropertyChanged(nameof(SelectedItemsCount)); + } + } + } + + public ObservableCollection SelectedItems + { + get => _selectedItems; + set + { + if (_selectedItems != value) + { + _selectedItems = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(SelectedItemsCount)); + OnPropertyChanged(nameof(SelectedItemText)); + } + } + } + public int SelectedItemsCount + { + get + { + if (SelectionMode == SelectionMode.Single) + { + return SelectedItem != null ? 1 : 0; + } + else if (SelectionMode == SelectionMode.Multiple) + { + return SelectedItems?.Count ?? 0; + } + return 0; + + } + } + public string SelectedItemText + { + get + { + if (SelectionMode == SelectionMode.Single && SelectedItem is CollectionViewTestItem item) + { + return $"{item.Caption}"; + } + else if (SelectionMode == SelectionMode.Multiple && SelectedItems?.Count > 0) + { + var selectedCaptions = SelectedItems + .OfType() + .Select(i => i.Caption); + return string.Join(", ", selectedCaptions); + } + return "No items selected"; + } + } + + public int SelectionChangedEventCount + { + get => _selectionChangedEventCount; + set + { + _selectionChangedEventCount = value; + OnPropertyChanged(); + } + } + + public string PreviousSelectionText + { + get => _previousSelectionText; + set { _previousSelectionText = value; OnPropertyChanged(); } + } + + public string CurrentSelectionText + { + get => _currentSelectionText; + set { _currentSelectionText = value; OnPropertyChanged(); } + } + + public bool ItemsSourceStringItems + { + get => _itemsSourceStringItems; + set + { + _itemsSourceStringItems = value; + OnPropertyChanged(); + } + } public bool IsHeaderStringSelected { @@ -550,543 +550,543 @@ public bool IsItemTemplateSelected } private void LoadItems() - { - _observableCollection = new ObservableCollection(); - AddItems(_observableCollection, 7, "Fruits"); - AddItems(_observableCollection, 7, "Vegetables"); - - _observableCollection25 = new ObservableCollection(); - AddItems(_observableCollection25, 10, "Fruits"); - AddItems(_observableCollection25, 10, "Vegetables"); - - _observableCollection5 = new ObservableCollection(); - AddItems(_observableCollection5, 5, "Fruits"); - - _observableCollection2 = new ObservableCollection(); - AddItems(_observableCollection2, 10); - - _observableCollectionModel = new ObservableCollection(); - AddItems(_observableCollectionModel, 2, "Group A"); - AddItems(_observableCollectionModel, 1, "Group B"); - - _observableCollectionString = new ObservableCollection(); - AddItems(_observableCollectionString, 2, "Fruits"); - AddItems(_observableCollectionString, 2, "Vegetables"); - - _list = new List(); - AddItems(_list, 2, "Fruits"); - AddItems(_list, 2, "Vegetables"); - - _listModel = new List(); - AddItems(_listModel, 2, "Group A"); - - _groupedList = new List> - { - new Grouping("Fruits", new List()), - new Grouping("Vegetables", new List()) - }; - AddItems(_groupedList[0], 4, "Fruits"); - AddItems(_groupedList[1], 4, "Vegetables"); - - _observableCollection3 = new ObservableCollection(); - AddItems(_observableCollection3, 15, "Fruits"); - AddItems(_observableCollection3, 15, "Vegetables"); - - _groupedList3 = new List> - { - new Grouping("Fruits", new List()), - new Grouping("Vegetables", new List()) - - }; - AddItems(_groupedList3[0], 12, "Fruits"); - AddItems(_groupedList3[1], 12, "Vegetables"); - - _groupedList2 = new List> - { - new Grouping("Group1", new List()), - new Grouping("Group2", new List()) - }; - AddItems(_groupedList2[0], 3); - AddItems(_groupedList2[1], 2); - - _groupedListString = new List> - { - new Grouping("Fruits", new List()), - new Grouping("Vegetables", new List()) - }; - AddItems(_groupedListString[0], 3, "Fruits"); - AddItems(_groupedListString[1], 3, "Vegetables"); - - _groupedListModel = new List> - { - new Grouping("Group A", new List()), - new Grouping("Group B", new List()) - }; - AddItems(_groupedListModel[0], 1, "Group A"); - AddItems(_groupedListModel[1], 1, "Group B"); - - _emptyGroupedList = new List>(); - _emptyGroupedListModel = new List>(); - _emptyObservableCollection = new ObservableCollection(); - _emptyObservableCollectionModel = new ObservableCollection(); - } - - private void AddItems(IList list, int count, string category) - { - string[] fruits = - { - "Apple", "Banana", "Orange", "Grapes", "Mango", - "Pineapple", "Strawberry", "Blueberry", "Peach", "Cherry", - "Watermelon", "Papaya", "Kiwi", "Pear", "Plum", - "Avocado", "Fig", "Guava", "Lychee", "Pomegranate", - "Lime", "Lemon", "Coconut", "Apricot", "Blackberry" - }; - - string[] vegetables = - { - "Carrot", "Broccoli", "Spinach", "Potato", "Tomato", - "Cucumber", "Lettuce", "Onion", "Garlic", "Pepper", - "Zucchini", "Pumpkin", "Radish", "Beetroot", "Cabbage", - "Sweet Potato", "Turnip", "Cauliflower", "Celery", "Asparagus", - "Eggplant", "Chili", "Corn", "Peas", "Mushroom" - }; - - string[] items = category == "Fruits" ? fruits : vegetables; - - for (int n = 0; n < count; n++) - { - list.Add(new CollectionViewTestItem(items[n % items.Length], n)); - } - } - - private void AddItems(IList list, int count, string category) - { - string[] groupA = - { - "dotnet_bot.png", - "calculator.png", - "blue.png", - "bank.png", - }; - string[] groupB = - { - "avatar.png", - "coffee.png", - "cover1.jpg", - "menu_icon.png", - }; - string[] imageItems = category == "Group A" ? groupA : groupB; - - for (int n = 0; n < count; n++) - { - list.Add(new CollectionViewTestModelItem( - $"{imageItems[n % imageItems.Length]}", imageItems[n % imageItems.Length], n)); - } - } - - private void AddItems(IList list, int count) - { - string loremParagraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; - string[] sentences = loremParagraph.Split(new[] { ". " }, StringSplitOptions.RemoveEmptyEntries); - - double fixedFontSize = 16; - - for (int i = 0; i < count; i++) - { - int sentenceCount = (i % sentences.Length) + 1; - string text = string.Join(". ", sentences.Take(sentenceCount)) + "."; - list.Add(new ItemModel(text, fixedFontSize)); - } - } - - private void AddItem() - { - if (_addIndex >= _addSequenceFruits.Length) - _addIndex = 0; - - var fruitName = _addSequenceFruits[_addIndex++]; - var newItem = new CollectionViewTestItem(fruitName, _addIndex - 1); - - if (ItemsSourceType == ItemsSourceType.ObservableCollectionT3) - { - _observableCollection3.Insert(0, newItem); - } - else if (ItemsSourceType == ItemsSourceType.GroupedListT3 && _groupedList3.Count > 0) - { - _groupedList3[0].Insert(0, newItem); - } - - OnPropertyChanged(nameof(ItemsSource)); - } - - private void SetItemTemplate() - { - if (ItemsSourceType == ItemsSourceType.ObservableCollectionT2 || ItemsSourceType == ItemsSourceType.GroupedListT2) - { - - ItemTemplate = new DataTemplate(() => - { - var stackLayout = new StackLayout - { - BackgroundColor = Colors.LightBlue, - Margin = new Thickness(1), - - }; - - var label = new Label - { - TextColor = Colors.Black - }; - - label.SetBinding(Label.TextProperty, "Caption"); - label.SetBinding(Label.FontSizeProperty, "FontSize"); - - stackLayout.Children.Add(label); - - return stackLayout; - }); - } - else if (ItemsSourceStringItems) - { - ItemTemplate = new DataTemplate(() => - { - var stackLayout = new StackLayout - { - Padding = new Thickness(10), - HorizontalOptions = LayoutOptions.Center, - VerticalOptions = LayoutOptions.Center - }; - - var label = new Label - { - VerticalOptions = LayoutOptions.Center, - HorizontalOptions = LayoutOptions.Center - }; - label.SetBinding(Label.TextProperty, "Caption"); - stackLayout.Children.Add(label); - return stackLayout; - }); - } - else if (!ItemsSourceStringItems) - { - ItemTemplate = ExampleTemplates.PhotoTemplate(); - } - else - { - ItemTemplate = new DataTemplate(() => - { - var stackLayout = new StackLayout - { - Padding = new Thickness(10), - HorizontalOptions = LayoutOptions.Center, - VerticalOptions = LayoutOptions.Center - }; - - var label = new Label - { - VerticalOptions = LayoutOptions.Center, - HorizontalOptions = LayoutOptions.Center - }; - label.SetBinding(Label.TextProperty, "Caption"); - stackLayout.Children.Add(label); - return stackLayout; - }); - } - } - - public void AddSequentialItem() - { - string[] fruits = { "Kiwi", "Guava", "Chikoo", "Raseberry", "Papaya", "Pineapple", "Strawberry", "Blueberry", "Peach", "Cherry" }; - string[] groupA = { "green.png", "groceries.png", "oasis.jpg", "seth.png", "test.jpg", "vegetables.jpg" }; - - string nextItem = ItemsSourceType switch - { - ItemsSourceType.ObservableCollectionStringT or ItemsSourceType.GroupedListStringT => fruits[fruitIndex++ % fruits.Length], - ItemsSourceType.ObservableCollectionModelT or ItemsSourceType.GroupedListModelT => groupA[groupAIndex++ % groupA.Length], - _ => string.Empty - }; - - switch (ItemsSourceType) - { - case ItemsSourceType.ObservableCollectionStringT: - _observableCollectionString.Add(new CollectionViewTestItem(nextItem, _observableCollectionString.Count)); - break; - - case ItemsSourceType.ObservableCollectionModelT: - _observableCollectionModel.Add(new CollectionViewTestModelItem(nextItem, nextItem, _observableCollectionModel.Count)); - break; - - case ItemsSourceType.GroupedListStringT: - if (_groupedListString.Count > 1) - { - int targetGroupIndex = _groupedListString[0].Count <= _groupedListString[1].Count ? 0 : 1; - _groupedListString[targetGroupIndex].Add(new CollectionViewTestItem(nextItem, _groupedListString[targetGroupIndex].Count)); - } - else if (_groupedListString.Count > 0) - { - _groupedListString[0].Add(new CollectionViewTestItem(nextItem, _groupedListString[0].Count)); - } - break; - - case ItemsSourceType.GroupedListModelT: - if (_groupedListModel.Count > 1) - { - int targetGroupIndex = _groupedListModel[0].Count <= _groupedListModel[1].Count ? 0 : 1; - _groupedListModel[targetGroupIndex].Add(new CollectionViewTestModelItem(nextItem, nextItem, _groupedListModel[targetGroupIndex].Count)); - } - else if (_groupedListModel.Count > 0) - { - _groupedListModel[0].Add(new CollectionViewTestModelItem(nextItem, nextItem, _groupedListModel[0].Count)); - } - break; - } - - OnPropertyChanged(nameof(ItemsSource)); - } - - public void RemoveLastItem() - { - object deletedItem = null; - switch (ItemsSourceType) - { - case ItemsSourceType.ObservableCollectionStringT: - if (_observableCollectionString.Count > 0) - { - deletedItem = _observableCollectionString[^1]; - _observableCollectionString.RemoveAt(_observableCollectionString.Count - 1); - } - break; - - case ItemsSourceType.ObservableCollectionModelT: - if (_observableCollectionModel.Count > 0) - { - deletedItem = _observableCollectionModel[^1]; - _observableCollectionModel.RemoveAt(_observableCollectionModel.Count - 1); - } - break; - - case ItemsSourceType.GroupedListStringT: - if (_groupedListString.Count > 0) - { - int targetGroupIndex = (_groupedListString[0].Count > 0) ? 0 : 1; - - if (targetGroupIndex < _groupedListString.Count && _groupedListString[targetGroupIndex].Count > 0) - { - deletedItem = _groupedListString[targetGroupIndex][^1]; - _groupedListString[targetGroupIndex].RemoveAt(_groupedListString[targetGroupIndex].Count - 1); - } - } - break; - - case ItemsSourceType.GroupedListModelT: - if (_groupedListModel.Count > 0) - { - int targetGroupIndex = (_groupedListModel[0].Count > 0) ? 0 : 1; - - if (targetGroupIndex < _groupedListModel.Count && _groupedListModel[targetGroupIndex].Count > 0) - { - deletedItem = _groupedListModel[targetGroupIndex][^1]; - _groupedListModel[targetGroupIndex].RemoveAt(_groupedListModel[targetGroupIndex].Count - 1); - } - } - break; - } - - if (deletedItem != null) - { - if (SelectedItems.Contains(deletedItem)) - { - SelectedItems.Remove(deletedItem); - } - - if (SelectedItem == deletedItem) - { - SelectedItem = null; - } - } - - OnPropertyChanged(nameof(ItemsSource)); - } - - public void AddItemAtIndex(int index) - { - string[] fruits = { "Kiwi", "Guava", "Chikoo", "Raseberry", "Papaya", "Pineapple", "Strawberry", "Blueberry", "Peach", "Cherry" }; - string[] groupA = { "green.png", "groceries.png", "oasis.jpg", "seth.png", "test.jpg", "vegetables.jpg" }; - - string sequentialItem = fruits[index % fruits.Length]; - string sequentialImageItem = groupA[index % groupA.Length]; - - switch (ItemsSourceType) - { - case ItemsSourceType.ObservableCollectionStringT: - if (index >= 0 && index <= _observableCollectionString.Count) - { - _observableCollectionString.Insert(index, new CollectionViewTestItem(sequentialItem, index)); - } - break; - - case ItemsSourceType.ObservableCollectionModelT: - if (index >= 0 && index <= _observableCollectionModel.Count) - { - _observableCollectionModel.Insert(index, new CollectionViewTestModelItem(sequentialImageItem, sequentialImageItem, index)); - } - break; - - case ItemsSourceType.GroupedListStringT: - if (_groupedListString.Count > 0 && index >= 0 && index <= _groupedListString[0].Count) - { - _groupedListString[0].Insert(index, new CollectionViewTestItem(sequentialItem, index)); - } - break; - - case ItemsSourceType.GroupedListModelT: - if (_groupedListModel.Count > 0 && index >= 0 && index <= _groupedListModel[0].Count) - { - _groupedListModel[0].Insert(index, new CollectionViewTestModelItem(sequentialImageItem, sequentialImageItem, index)); - } - break; - } - - OnPropertyChanged(nameof(ItemsSource)); - } - public void RemoveItemAtIndex(int index) - { - object deletedItem = null; - - switch (ItemsSourceType) - { - case ItemsSourceType.ObservableCollectionStringT: - if (index >= 0 && index < _observableCollectionString.Count) - { - deletedItem = _observableCollectionString[index]; - _observableCollectionString.RemoveAt(index); - } - break; - - case ItemsSourceType.ObservableCollectionModelT: - if (index >= 0 && index < _observableCollectionModel.Count) - { - deletedItem = _observableCollectionModel[index]; - _observableCollectionModel.RemoveAt(index); - } - break; - - case ItemsSourceType.GroupedListStringT: - if (_groupedListString.Count > 0) - { - if (index >= 0 && index < _groupedListString[0].Count) - { - deletedItem = _groupedListString[0][index]; - _groupedListString[0].RemoveAt(index); - } - else if (_groupedListString.Count > 1 && index >= 0 && index < _groupedListString[1].Count) - { - deletedItem = _groupedListString[1][index]; - _groupedListString[1].RemoveAt(index); - } - } - break; - - case ItemsSourceType.GroupedListModelT: - if (_groupedListModel.Count > 0) - { - if (index >= 0 && index < _groupedListModel[0].Count) - { - deletedItem = _groupedListModel[0][index]; - _groupedListModel[0].RemoveAt(index); - } - else if (_groupedListModel.Count > 1 && index >= 0 && index < _groupedListModel[1].Count) - { - deletedItem = _groupedListModel[1][index]; - _groupedListModel[1].RemoveAt(index); - } - } - break; - } - - if (deletedItem != null) - { - if (SelectedItems.Contains(deletedItem)) - { - SelectedItems.Remove(deletedItem); - } - - if (SelectedItem == deletedItem) - { - SelectedItem = null; - } - } - - OnPropertyChanged(nameof(ItemsSource)); - } - - private void OnSelectedItemsChanged(object sender, NotifyCollectionChangedEventArgs e) - { - OnPropertyChanged(nameof(SelectedItemsCount)); - OnPropertyChanged(nameof(SelectedItemText)); - } - - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - if (propertyName == nameof(IsGrouped)) - { - OnPropertyChanged(nameof(ItemsSource)); - } - - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - public class CustomDataTemplateSelector : DataTemplateSelector - { - public DataTemplate Template1 { get; set; } - public DataTemplate Template2 { get; set; } - - protected override DataTemplate OnSelectTemplate(object item, BindableObject container) - { - if (item is CollectionViewTestItem testItem) - { - return testItem.Index % 2 == 0 ? Template1 : Template2; - } - - return Template1; - } - } - - public class CollectionViewTestItem - { - public string Caption { get; set; } - public int Index { get; set; } - - public CollectionViewTestItem(string caption, int index) - { - Caption = caption; - Index = index; - } - } - - public class CollectionViewTestModelItem - { - public string Caption { get; set; } - public string Image { get; set; } - public int Index { get; set; } - - public CollectionViewTestModelItem(string caption, string image, int index) - { - Caption = caption; - Image = image; - Index = index; - } - } - - public class ItemModel - { - public string Caption { get; set; } - public double FontSize { get; set; } - - public ItemModel(string caption, double fontSize) - { - Caption = caption; - FontSize = fontSize; - } - } + { + _observableCollection = new ObservableCollection(); + AddItems(_observableCollection, 7, "Fruits"); + AddItems(_observableCollection, 7, "Vegetables"); + + _observableCollection25 = new ObservableCollection(); + AddItems(_observableCollection25, 10, "Fruits"); + AddItems(_observableCollection25, 10, "Vegetables"); + + _observableCollection5 = new ObservableCollection(); + AddItems(_observableCollection5, 5, "Fruits"); + + _observableCollection2 = new ObservableCollection(); + AddItems(_observableCollection2, 10); + + _observableCollectionModel = new ObservableCollection(); + AddItems(_observableCollectionModel, 2, "Group A"); + AddItems(_observableCollectionModel, 1, "Group B"); + + _observableCollectionString = new ObservableCollection(); + AddItems(_observableCollectionString, 2, "Fruits"); + AddItems(_observableCollectionString, 2, "Vegetables"); + + _list = new List(); + AddItems(_list, 2, "Fruits"); + AddItems(_list, 2, "Vegetables"); + + _listModel = new List(); + AddItems(_listModel, 2, "Group A"); + + _groupedList = new List> + { + new Grouping("Fruits", new List()), + new Grouping("Vegetables", new List()) + }; + AddItems(_groupedList[0], 4, "Fruits"); + AddItems(_groupedList[1], 4, "Vegetables"); + + _observableCollection3 = new ObservableCollection(); + AddItems(_observableCollection3, 15, "Fruits"); + AddItems(_observableCollection3, 15, "Vegetables"); + + _groupedList3 = new List> + { + new Grouping("Fruits", new List()), + new Grouping("Vegetables", new List()) + + }; + AddItems(_groupedList3[0], 12, "Fruits"); + AddItems(_groupedList3[1], 12, "Vegetables"); + + _groupedList2 = new List> + { + new Grouping("Group1", new List()), + new Grouping("Group2", new List()) + }; + AddItems(_groupedList2[0], 3); + AddItems(_groupedList2[1], 2); + + _groupedListString = new List> + { + new Grouping("Fruits", new List()), + new Grouping("Vegetables", new List()) + }; + AddItems(_groupedListString[0], 3, "Fruits"); + AddItems(_groupedListString[1], 3, "Vegetables"); + + _groupedListModel = new List> + { + new Grouping("Group A", new List()), + new Grouping("Group B", new List()) + }; + AddItems(_groupedListModel[0], 1, "Group A"); + AddItems(_groupedListModel[1], 1, "Group B"); + + _emptyGroupedList = new List>(); + _emptyGroupedListModel = new List>(); + _emptyObservableCollection = new ObservableCollection(); + _emptyObservableCollectionModel = new ObservableCollection(); + } + + private void AddItems(IList list, int count, string category) + { + string[] fruits = + { + "Apple", "Banana", "Orange", "Grapes", "Mango", + "Pineapple", "Strawberry", "Blueberry", "Peach", "Cherry", + "Watermelon", "Papaya", "Kiwi", "Pear", "Plum", + "Avocado", "Fig", "Guava", "Lychee", "Pomegranate", + "Lime", "Lemon", "Coconut", "Apricot", "Blackberry" + }; + + string[] vegetables = + { + "Carrot", "Broccoli", "Spinach", "Potato", "Tomato", + "Cucumber", "Lettuce", "Onion", "Garlic", "Pepper", + "Zucchini", "Pumpkin", "Radish", "Beetroot", "Cabbage", + "Sweet Potato", "Turnip", "Cauliflower", "Celery", "Asparagus", + "Eggplant", "Chili", "Corn", "Peas", "Mushroom" + }; + + string[] items = category == "Fruits" ? fruits : vegetables; + + for (int n = 0; n < count; n++) + { + list.Add(new CollectionViewTestItem(items[n % items.Length], n)); + } + } + + private void AddItems(IList list, int count, string category) + { + string[] groupA = + { + "dotnet_bot.png", + "calculator.png", + "blue.png", + "bank.png", + }; + string[] groupB = + { + "avatar.png", + "coffee.png", + "cover1.jpg", + "menu_icon.png", + }; + string[] imageItems = category == "Group A" ? groupA : groupB; + + for (int n = 0; n < count; n++) + { + list.Add(new CollectionViewTestModelItem( + $"{imageItems[n % imageItems.Length]}", imageItems[n % imageItems.Length], n)); + } + } + + private void AddItems(IList list, int count) + { + string loremParagraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; + string[] sentences = loremParagraph.Split(new[] { ". " }, StringSplitOptions.RemoveEmptyEntries); + + double fixedFontSize = 16; + + for (int i = 0; i < count; i++) + { + int sentenceCount = (i % sentences.Length) + 1; + string text = string.Join(". ", sentences.Take(sentenceCount)) + "."; + list.Add(new ItemModel(text, fixedFontSize)); + } + } + + private void AddItem() + { + if (_addIndex >= _addSequenceFruits.Length) + _addIndex = 0; + + var fruitName = _addSequenceFruits[_addIndex++]; + var newItem = new CollectionViewTestItem(fruitName, _addIndex - 1); + + if (ItemsSourceType == ItemsSourceType.ObservableCollectionT3) + { + _observableCollection3.Insert(0, newItem); + } + else if (ItemsSourceType == ItemsSourceType.GroupedListT3 && _groupedList3.Count > 0) + { + _groupedList3[0].Insert(0, newItem); + } + + OnPropertyChanged(nameof(ItemsSource)); + } + + private void SetItemTemplate() + { + if (ItemsSourceType == ItemsSourceType.ObservableCollectionT2 || ItemsSourceType == ItemsSourceType.GroupedListT2) + { + + ItemTemplate = new DataTemplate(() => + { + var stackLayout = new StackLayout + { + BackgroundColor = Colors.LightBlue, + Margin = new Thickness(1), + + }; + + var label = new Label + { + TextColor = Colors.Black + }; + + label.SetBinding(Label.TextProperty, "Caption"); + label.SetBinding(Label.FontSizeProperty, "FontSize"); + + stackLayout.Children.Add(label); + + return stackLayout; + }); + } + else if (ItemsSourceStringItems) + { + ItemTemplate = new DataTemplate(() => + { + var stackLayout = new StackLayout + { + Padding = new Thickness(10), + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + + var label = new Label + { + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center + }; + label.SetBinding(Label.TextProperty, "Caption"); + stackLayout.Children.Add(label); + return stackLayout; + }); + } + else if (!ItemsSourceStringItems) + { + ItemTemplate = ExampleTemplates.PhotoTemplate(); + } + else + { + ItemTemplate = new DataTemplate(() => + { + var stackLayout = new StackLayout + { + Padding = new Thickness(10), + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + + var label = new Label + { + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center + }; + label.SetBinding(Label.TextProperty, "Caption"); + stackLayout.Children.Add(label); + return stackLayout; + }); + } + } + + public void AddSequentialItem() + { + string[] fruits = { "Kiwi", "Guava", "Chikoo", "Raseberry", "Papaya", "Pineapple", "Strawberry", "Blueberry", "Peach", "Cherry" }; + string[] groupA = { "green.png", "groceries.png", "oasis.jpg", "seth.png", "test.jpg", "vegetables.jpg" }; + + string nextItem = ItemsSourceType switch + { + ItemsSourceType.ObservableCollectionStringT or ItemsSourceType.GroupedListStringT => fruits[fruitIndex++ % fruits.Length], + ItemsSourceType.ObservableCollectionModelT or ItemsSourceType.GroupedListModelT => groupA[groupAIndex++ % groupA.Length], + _ => string.Empty + }; + + switch (ItemsSourceType) + { + case ItemsSourceType.ObservableCollectionStringT: + _observableCollectionString.Add(new CollectionViewTestItem(nextItem, _observableCollectionString.Count)); + break; + + case ItemsSourceType.ObservableCollectionModelT: + _observableCollectionModel.Add(new CollectionViewTestModelItem(nextItem, nextItem, _observableCollectionModel.Count)); + break; + + case ItemsSourceType.GroupedListStringT: + if (_groupedListString.Count > 1) + { + int targetGroupIndex = _groupedListString[0].Count <= _groupedListString[1].Count ? 0 : 1; + _groupedListString[targetGroupIndex].Add(new CollectionViewTestItem(nextItem, _groupedListString[targetGroupIndex].Count)); + } + else if (_groupedListString.Count > 0) + { + _groupedListString[0].Add(new CollectionViewTestItem(nextItem, _groupedListString[0].Count)); + } + break; + + case ItemsSourceType.GroupedListModelT: + if (_groupedListModel.Count > 1) + { + int targetGroupIndex = _groupedListModel[0].Count <= _groupedListModel[1].Count ? 0 : 1; + _groupedListModel[targetGroupIndex].Add(new CollectionViewTestModelItem(nextItem, nextItem, _groupedListModel[targetGroupIndex].Count)); + } + else if (_groupedListModel.Count > 0) + { + _groupedListModel[0].Add(new CollectionViewTestModelItem(nextItem, nextItem, _groupedListModel[0].Count)); + } + break; + } + + OnPropertyChanged(nameof(ItemsSource)); + } + + public void RemoveLastItem() + { + object deletedItem = null; + switch (ItemsSourceType) + { + case ItemsSourceType.ObservableCollectionStringT: + if (_observableCollectionString.Count > 0) + { + deletedItem = _observableCollectionString[^1]; + _observableCollectionString.RemoveAt(_observableCollectionString.Count - 1); + } + break; + + case ItemsSourceType.ObservableCollectionModelT: + if (_observableCollectionModel.Count > 0) + { + deletedItem = _observableCollectionModel[^1]; + _observableCollectionModel.RemoveAt(_observableCollectionModel.Count - 1); + } + break; + + case ItemsSourceType.GroupedListStringT: + if (_groupedListString.Count > 0) + { + int targetGroupIndex = (_groupedListString[0].Count > 0) ? 0 : 1; + + if (targetGroupIndex < _groupedListString.Count && _groupedListString[targetGroupIndex].Count > 0) + { + deletedItem = _groupedListString[targetGroupIndex][^1]; + _groupedListString[targetGroupIndex].RemoveAt(_groupedListString[targetGroupIndex].Count - 1); + } + } + break; + + case ItemsSourceType.GroupedListModelT: + if (_groupedListModel.Count > 0) + { + int targetGroupIndex = (_groupedListModel[0].Count > 0) ? 0 : 1; + + if (targetGroupIndex < _groupedListModel.Count && _groupedListModel[targetGroupIndex].Count > 0) + { + deletedItem = _groupedListModel[targetGroupIndex][^1]; + _groupedListModel[targetGroupIndex].RemoveAt(_groupedListModel[targetGroupIndex].Count - 1); + } + } + break; + } + + if (deletedItem != null) + { + if (SelectedItems.Contains(deletedItem)) + { + SelectedItems.Remove(deletedItem); + } + + if (SelectedItem == deletedItem) + { + SelectedItem = null; + } + } + + OnPropertyChanged(nameof(ItemsSource)); + } + + public void AddItemAtIndex(int index) + { + string[] fruits = { "Kiwi", "Guava", "Chikoo", "Raseberry", "Papaya", "Pineapple", "Strawberry", "Blueberry", "Peach", "Cherry" }; + string[] groupA = { "green.png", "groceries.png", "oasis.jpg", "seth.png", "test.jpg", "vegetables.jpg" }; + + string sequentialItem = fruits[index % fruits.Length]; + string sequentialImageItem = groupA[index % groupA.Length]; + + switch (ItemsSourceType) + { + case ItemsSourceType.ObservableCollectionStringT: + if (index >= 0 && index <= _observableCollectionString.Count) + { + _observableCollectionString.Insert(index, new CollectionViewTestItem(sequentialItem, index)); + } + break; + + case ItemsSourceType.ObservableCollectionModelT: + if (index >= 0 && index <= _observableCollectionModel.Count) + { + _observableCollectionModel.Insert(index, new CollectionViewTestModelItem(sequentialImageItem, sequentialImageItem, index)); + } + break; + + case ItemsSourceType.GroupedListStringT: + if (_groupedListString.Count > 0 && index >= 0 && index <= _groupedListString[0].Count) + { + _groupedListString[0].Insert(index, new CollectionViewTestItem(sequentialItem, index)); + } + break; + + case ItemsSourceType.GroupedListModelT: + if (_groupedListModel.Count > 0 && index >= 0 && index <= _groupedListModel[0].Count) + { + _groupedListModel[0].Insert(index, new CollectionViewTestModelItem(sequentialImageItem, sequentialImageItem, index)); + } + break; + } + + OnPropertyChanged(nameof(ItemsSource)); + } + public void RemoveItemAtIndex(int index) + { + object deletedItem = null; + + switch (ItemsSourceType) + { + case ItemsSourceType.ObservableCollectionStringT: + if (index >= 0 && index < _observableCollectionString.Count) + { + deletedItem = _observableCollectionString[index]; + _observableCollectionString.RemoveAt(index); + } + break; + + case ItemsSourceType.ObservableCollectionModelT: + if (index >= 0 && index < _observableCollectionModel.Count) + { + deletedItem = _observableCollectionModel[index]; + _observableCollectionModel.RemoveAt(index); + } + break; + + case ItemsSourceType.GroupedListStringT: + if (_groupedListString.Count > 0) + { + if (index >= 0 && index < _groupedListString[0].Count) + { + deletedItem = _groupedListString[0][index]; + _groupedListString[0].RemoveAt(index); + } + else if (_groupedListString.Count > 1 && index >= 0 && index < _groupedListString[1].Count) + { + deletedItem = _groupedListString[1][index]; + _groupedListString[1].RemoveAt(index); + } + } + break; + + case ItemsSourceType.GroupedListModelT: + if (_groupedListModel.Count > 0) + { + if (index >= 0 && index < _groupedListModel[0].Count) + { + deletedItem = _groupedListModel[0][index]; + _groupedListModel[0].RemoveAt(index); + } + else if (_groupedListModel.Count > 1 && index >= 0 && index < _groupedListModel[1].Count) + { + deletedItem = _groupedListModel[1][index]; + _groupedListModel[1].RemoveAt(index); + } + } + break; + } + + if (deletedItem != null) + { + if (SelectedItems.Contains(deletedItem)) + { + SelectedItems.Remove(deletedItem); + } + + if (SelectedItem == deletedItem) + { + SelectedItem = null; + } + } + + OnPropertyChanged(nameof(ItemsSource)); + } + + private void OnSelectedItemsChanged(object sender, NotifyCollectionChangedEventArgs e) + { + OnPropertyChanged(nameof(SelectedItemsCount)); + OnPropertyChanged(nameof(SelectedItemText)); + } + + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + if (propertyName == nameof(IsGrouped)) + { + OnPropertyChanged(nameof(ItemsSource)); + } + + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public class CustomDataTemplateSelector : DataTemplateSelector + { + public DataTemplate Template1 { get; set; } + public DataTemplate Template2 { get; set; } + + protected override DataTemplate OnSelectTemplate(object item, BindableObject container) + { + if (item is CollectionViewTestItem testItem) + { + return testItem.Index % 2 == 0 ? Template1 : Template2; + } + + return Template1; + } + } + + public class CollectionViewTestItem + { + public string Caption { get; set; } + public int Index { get; set; } + + public CollectionViewTestItem(string caption, int index) + { + Caption = caption; + Index = index; + } + } + + public class CollectionViewTestModelItem + { + public string Caption { get; set; } + public string Image { get; set; } + public int Index { get; set; } + + public CollectionViewTestModelItem(string caption, string image, int index) + { + Caption = caption; + Image = image; + Index = index; + } + } + + public class ItemModel + { + public string Caption { get; set; } + public double FontSize { get; set; } + + public ItemModel(string caption, double fontSize) + { + Caption = caption; + FontSize = fontSize; + } + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/ItemsSource/CollectionViewItemsSourcePage.xaml.cs b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/ItemsSource/CollectionViewItemsSourcePage.xaml.cs index 3c86be120139..157df9015307 100644 --- a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/ItemsSource/CollectionViewItemsSourcePage.xaml.cs +++ b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/ItemsSource/CollectionViewItemsSourcePage.xaml.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using Microsoft.Maui.Controls; using Microsoft.Maui.Graphics; -using System.Collections.Specialized; namespace Maui.Controls.Sample; diff --git a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Stepper/StepperFeaturePage.xaml.cs b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Stepper/StepperFeaturePage.xaml.cs index d53c97f04004..26a6164ba5e7 100644 --- a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Stepper/StepperFeaturePage.xaml.cs +++ b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Stepper/StepperFeaturePage.xaml.cs @@ -5,64 +5,64 @@ namespace Maui.Controls.Sample; public partial class StepperFeaturePage : ContentPage { - private StepperViewModel _viewModel; + private StepperViewModel _viewModel; - public StepperFeaturePage(StepperViewModel viewModel) - { - InitializeComponent(); - _viewModel = viewModel; - BindingContext = _viewModel; - } + public StepperFeaturePage(StepperViewModel viewModel) + { + InitializeComponent(); + _viewModel = viewModel; + BindingContext = _viewModel; + } - private void ApplyButton_Clicked(object sender, EventArgs e) - { - Navigation.PopAsync(); - } + private void ApplyButton_Clicked(object sender, EventArgs e) + { + Navigation.PopAsync(); + } - private void OnMinimumChanged(object sender, TextChangedEventArgs e) - { - if (double.TryParse(MinimumEntry.Text, out double min)) - { - _viewModel.Minimum = min; - } - } + private void OnMinimumChanged(object sender, TextChangedEventArgs e) + { + if (double.TryParse(MinimumEntry.Text, out double min)) + { + _viewModel.Minimum = min; + } + } - private void OnMaximumChanged(object sender, TextChangedEventArgs e) - { - if (double.TryParse(MaximumEntry.Text, out double max)) - { - _viewModel.Maximum = max; - } - } + private void OnMaximumChanged(object sender, TextChangedEventArgs e) + { + if (double.TryParse(MaximumEntry.Text, out double max)) + { + _viewModel.Maximum = max; + } + } - private void OnIncrementChanged(object sender, TextChangedEventArgs e) - { - if (double.TryParse(IncrementEntry.Text, out double increment)) - { - _viewModel.Increment = increment; - } - } + private void OnIncrementChanged(object sender, TextChangedEventArgs e) + { + if (double.TryParse(IncrementEntry.Text, out double increment)) + { + _viewModel.Increment = increment; + } + } - private void OnValueChanged(object sender, TextChangedEventArgs e) - { - if (double.TryParse(ValueEntry.Text, out double value)) - { - _viewModel.Value = value; - } - } + private void OnValueChanged(object sender, TextChangedEventArgs e) + { + if (double.TryParse(ValueEntry.Text, out double value)) + { + _viewModel.Value = value; + } + } - private void OnIsEnabledCheckedChanged(object sender, CheckedChangedEventArgs e) - { - _viewModel.IsEnabled = IsEnabledTrueRadio.IsChecked; - } + private void OnIsEnabledCheckedChanged(object sender, CheckedChangedEventArgs e) + { + _viewModel.IsEnabled = IsEnabledTrueRadio.IsChecked; + } - private void OnIsVisibleCheckedChanged(object sender, CheckedChangedEventArgs e) - { - _viewModel.IsVisible = IsVisibleTrueRadio.IsChecked; - } + private void OnIsVisibleCheckedChanged(object sender, CheckedChangedEventArgs e) + { + _viewModel.IsVisible = IsVisibleTrueRadio.IsChecked; + } - private void OnFlowDirectionChanged(object sender, CheckedChangedEventArgs e) - { - _viewModel.FlowDirection = FlowDirectionLTRRadio.IsChecked ? FlowDirection.LeftToRight : FlowDirection.RightToLeft; - } + private void OnFlowDirectionChanged(object sender, CheckedChangedEventArgs e) + { + _viewModel.FlowDirection = FlowDirectionLTRRadio.IsChecked ? FlowDirection.LeftToRight : FlowDirection.RightToLeft; + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Stepper/StepperViewModel.cs b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Stepper/StepperViewModel.cs index e51ff5f6fdfa..c0a1e027c57d 100644 --- a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Stepper/StepperViewModel.cs +++ b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Stepper/StepperViewModel.cs @@ -5,64 +5,64 @@ namespace Maui.Controls.Sample; public class StepperViewModel : INotifyPropertyChanged { - private double _minimum = 0; - private double _maximum = 10; - private double _increment = 1; - private double _value = 0; - private bool _isEnabled = true; - private bool _isVisible = true; - private FlowDirection _flowDirection = FlowDirection.LeftToRight; + private double _minimum = 0; + private double _maximum = 10; + private double _increment = 1; + private double _value = 0; + private bool _isEnabled = true; + private bool _isVisible = true; + private FlowDirection _flowDirection = FlowDirection.LeftToRight; - public double Minimum - { - get => _minimum; - set => SetProperty(ref _minimum, value); - } + public double Minimum + { + get => _minimum; + set => SetProperty(ref _minimum, value); + } - public double Maximum - { - get => _maximum; - set => SetProperty(ref _maximum, value); - } + public double Maximum + { + get => _maximum; + set => SetProperty(ref _maximum, value); + } - public double Increment - { - get => _increment; - set => SetProperty(ref _increment, value); - } + public double Increment + { + get => _increment; + set => SetProperty(ref _increment, value); + } - public double Value - { - get => _value; - set => SetProperty(ref _value, value); - } + public double Value + { + get => _value; + set => SetProperty(ref _value, value); + } - public bool IsEnabled - { - get => _isEnabled; - set => SetProperty(ref _isEnabled, value); - } + public bool IsEnabled + { + get => _isEnabled; + set => SetProperty(ref _isEnabled, value); + } - public bool IsVisible - { - get => _isVisible; - set => SetProperty(ref _isVisible, value); - } + public bool IsVisible + { + get => _isVisible; + set => SetProperty(ref _isVisible, value); + } - public FlowDirection FlowDirection - { - get => _flowDirection; - set => SetProperty(ref _flowDirection, value); - } + public FlowDirection FlowDirection + { + get => _flowDirection; + set => SetProperty(ref _flowDirection, value); + } - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler PropertyChanged; - protected void SetProperty(ref T backingStore, T value, [CallerMemberName] string propertyName = "") - { - if (EqualityComparer.Default.Equals(backingStore, value)) - return; + protected void SetProperty(ref T backingStore, T value, [CallerMemberName] string propertyName = "") + { + if (EqualityComparer.Default.Equals(backingStore, value)) + return; - backingStore = value; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } + backingStore = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue15154.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue15154.cs index 352b888b2fc5..030fc4371dbc 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue15154.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue15154.cs @@ -5,53 +5,53 @@ public class Issue15154 : Shell { public Issue15154() { - this.Items.Add(new ShellContent - { - Title = "EmptyView Template with behavior with height", - ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) - }); - - this.Items.Add(new ShellContent - { - Title = "EmptyView Template Grid", - ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) - }); - - this.Items.Add(new ShellContent - { - Title = "EmptyView Template Grid with behavior with height", - ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) - }); - - this.Items.Add(new ShellContent - { - Title = "EmptyView Template Grid with behavior without height", - ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) - }); - - this.Items.Add(new ShellContent - { - Title = "EmptyView Text ScrollView", - ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) - }); - - this.Items.Add(new ShellContent - { - Title = "EmptyView Template ScrollView", - ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) - }); - - this.Items.Add(new ShellContent - { - Title = "EmptyView Text ScrollView with behavior with height", - ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) - }); - - this.Items.Add(new ShellContent - { - Title = "EmptyView Text ScrollView without behavior with height", - ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) - }); + this.Items.Add(new ShellContent + { + Title = "EmptyView Template with behavior with height", + ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) + }); + + this.Items.Add(new ShellContent + { + Title = "EmptyView Template Grid", + ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) + }); + + this.Items.Add(new ShellContent + { + Title = "EmptyView Template Grid with behavior with height", + ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) + }); + + this.Items.Add(new ShellContent + { + Title = "EmptyView Template Grid with behavior without height", + ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) + }); + + this.Items.Add(new ShellContent + { + Title = "EmptyView Text ScrollView", + ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) + }); + + this.Items.Add(new ShellContent + { + Title = "EmptyView Template ScrollView", + ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) + }); + + this.Items.Add(new ShellContent + { + Title = "EmptyView Text ScrollView with behavior with height", + ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) + }); + + this.Items.Add(new ShellContent + { + Title = "EmptyView Text ScrollView without behavior with height", + ContentTemplate = new DataTemplate(typeof(Issue15154_MainPage)) + }); } public class Issue15154_MainPage : ContentPage diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue29609.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue29609.cs index 7e4fade76612..e47375326049 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue29609.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue29609.cs @@ -5,68 +5,68 @@ namespace Maui.Controls.Sample.Issues; [Issue(IssueTracker.Github, 29609, "ItemSpacing on CarouselView resizes items", PlatformAffected.Android)] public class Issue29609 : ContentPage { - Issue29609_ViewModel ViewModel; - public Issue29609() - { - ViewModel = new Issue29609_ViewModel(); - BindingContext = ViewModel; - var stack = new StackLayout - { - VerticalOptions = LayoutOptions.Center, - HorizontalOptions = LayoutOptions.Center - }; - var label = new Label - { - Text = "ItemSpacing on CarouselView resizes items", - AutomationId = "29609DescriptionLabel" - }; - var carouselView = new CarouselView - { - BackgroundColor = Colors.Red, - AutomationId = "29609CarouselView", - HeightRequest = 400, - WidthRequest = 300, - ItemsSource = ViewModel.Items, - Loop = false, - ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) - { - ItemSpacing = 50, - SnapPointsAlignment = SnapPointsAlignment.Center, - SnapPointsType = SnapPointsType.MandatorySingle - }, - ItemTemplate = new DataTemplate(() => - { - var grid = new Grid - { - BackgroundColor = Colors.Yellow - }; + Issue29609_ViewModel ViewModel; + public Issue29609() + { + ViewModel = new Issue29609_ViewModel(); + BindingContext = ViewModel; + var stack = new StackLayout + { + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center + }; + var label = new Label + { + Text = "ItemSpacing on CarouselView resizes items", + AutomationId = "29609DescriptionLabel" + }; + var carouselView = new CarouselView + { + BackgroundColor = Colors.Red, + AutomationId = "29609CarouselView", + HeightRequest = 400, + WidthRequest = 300, + ItemsSource = ViewModel.Items, + Loop = false, + ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) + { + ItemSpacing = 50, + SnapPointsAlignment = SnapPointsAlignment.Center, + SnapPointsType = SnapPointsType.MandatorySingle + }, + ItemTemplate = new DataTemplate(() => + { + var grid = new Grid + { + BackgroundColor = Colors.Yellow + }; - var label = new Label - { - HorizontalOptions = LayoutOptions.Center, - VerticalOptions = LayoutOptions.Center - }; - label.SetBinding(Label.TextProperty, "."); + var label = new Label + { + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + label.SetBinding(Label.TextProperty, "."); - grid.Children.Add(label); - return grid; - }) - }; - stack.Children.Add(label); - stack.Children.Add(carouselView); - Content = stack; - } + grid.Children.Add(label); + return grid; + }) + }; + stack.Children.Add(label); + stack.Children.Add(carouselView); + Content = stack; + } } public class Issue29609_ViewModel { - public ObservableCollection Items = new(); + public ObservableCollection Items = new(); - public Issue29609_ViewModel() - { - for (var i = 0; i < 5; i++) - { - Items.Add($"Item {i}"); - } - } + public Issue29609_ViewModel() + { + for (var i = 0; i < 5; i++) + { + Items.Add($"Item {i}"); + } + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_GroupingFeatureTests.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_GroupingFeatureTests.cs index fd8fe9f8274c..026ce7966f73 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_GroupingFeatureTests.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_GroupingFeatureTests.cs @@ -5,215 +5,215 @@ namespace Microsoft.Maui.TestCases.Tests; public class CollectionView_GroupingFeatureTests : UITest { - public const string GroupingFeatureMatrix = "CollectionView Feature Matrix"; - public const string Options = "Options"; - public const string Apply = "Apply"; - public const string GroupHeaderTemplateGrid = "GroupHeaderTemplateGrid"; - public const string GroupFooterTemplateGrid = "GroupFooterTemplateGrid"; - public const string IsGroupedTrue = "IsGroupedTrue"; - public const string ItemsSourceGroupedList = "ItemsSourceGroupedList"; - public const string FooterString = "FooterString"; - public const string HeaderString = "HeaderString"; - public const string ItemTemplateBasic = "ItemTemplateBasic"; - public const string ItemsLayoutHorizontalList = "ItemsLayoutHorizontalList"; - public const string ItemsLayoutHorizontalGrid = "ItemsLayoutHorizontalGrid"; - public const string ItemsLayoutVerticalGrid = "ItemsLayoutVerticalGrid"; - - - public CollectionView_GroupingFeatureTests(TestDevice device) - : base(device) - { - } - protected override void FixtureSetup() - { - base.FixtureSetup(); - App.NavigateToGallery(GroupingFeatureMatrix); - } - - [Test, Order(1)] - [Category(UITestCategories.CollectionView)] - public void VerifyGroupFooterTemplate_WithFooterString() - { - App.WaitForElement("GroupingButton"); - App.Tap("GroupingButton"); - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(GroupFooterTemplateGrid); - App.Tap(GroupFooterTemplateGrid); - App.WaitForElement(FooterString); - App.Tap(FooterString); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForElement("CollectionView Footer(String)"); - App.WaitForNoElement("GroupFooterTemplate"); - App.WaitForNoElement("GroupFooterTemplate"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyGroupFooterTemplate_WithHeaderString() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(GroupFooterTemplateGrid); - App.Tap(GroupFooterTemplateGrid); - App.WaitForElement(HeaderString); - App.Tap(HeaderString); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForElement("CollectionView Header(String)"); - App.WaitForNoElement("GroupFooterTemplate"); - App.WaitForNoElement("GroupFooterTemplate"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyGroupFooterTemplate_WithBasicItemTemplate() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(GroupFooterTemplateGrid); - App.Tap(GroupFooterTemplateGrid); - App.WaitForElement(ItemTemplateBasic); - App.Tap(ItemTemplateBasic); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForElement("Apple"); - App.WaitForElement("Banana"); - App.WaitForNoElement("GroupFooterTemplate"); - App.WaitForNoElement("GroupFooterTemplate"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyGroupHeaderTemplate_WithFooterString() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(GroupHeaderTemplateGrid); - App.Tap(GroupHeaderTemplateGrid); - App.WaitForElement(FooterString); - App.Tap(FooterString); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForElement("CollectionView Footer(String)"); - App.WaitForNoElement("GroupHeaderTemplate"); - App.WaitForNoElement("GroupHeaderTemplate"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyGroupHeaderTemplate_WithHeaderString() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(GroupHeaderTemplateGrid); - App.Tap(GroupHeaderTemplateGrid); - App.WaitForElement(HeaderString); - App.Tap(HeaderString); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForElement("CollectionView Header(String)"); - App.WaitForNoElement("GroupHeaderTemplate"); - App.WaitForNoElement("GroupHeaderTemplate"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyGroupHeaderTemplate_WithBasicItemTemplate() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(GroupHeaderTemplateGrid); - App.Tap(GroupHeaderTemplateGrid); - App.WaitForElement(ItemTemplateBasic); - App.Tap(ItemTemplateBasic); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForElement("Apple"); - App.WaitForElement("Banana"); - App.WaitForNoElement("GroupHeaderTemplate"); - App.WaitForNoElement("GroupHeaderTemplate"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyGroupHeaderAndFooterTemplate_WithObservableCollection() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(GroupHeaderTemplateGrid); - App.Tap(GroupHeaderTemplateGrid); - App.WaitForElement(GroupFooterTemplateGrid); - App.Tap(GroupFooterTemplateGrid); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForNoElement("GroupHeaderTemplate"); - App.WaitForNoElement("GroupHeaderTemplate"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyGroupHeaderAndFooterTemplate_WithItemSourceNull() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(GroupHeaderTemplateGrid); - App.Tap(GroupHeaderTemplateGrid); - App.WaitForElement(GroupFooterTemplateGrid); - App.Tap(GroupFooterTemplateGrid); - App.WaitForElement("ItemsSourceNone"); - App.Tap("ItemsSourceNone"); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForNoElement("GroupHeaderTemplate"); - App.WaitForNoElement("GroupFooterTemplate"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyIsGroupedFalse_WithItemSourceObservableCollection() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForElement("Apple"); - App.WaitForElement("Banana"); - App.WaitForNoElement("Fruits"); - App.WaitForNoElement("Vegetables"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyIsGroupedFalse_WithHeaderAndFooterString() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(HeaderString); - App.Tap(HeaderString); - App.WaitForElement(FooterString); - App.Tap(FooterString); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForElement("CollectionView Header(String)"); - App.WaitForElement("CollectionView Footer(String)"); - } - - [Test] - [Category(UITestCategories.CollectionView)] - public void VerifyIsGroupedFalse_WithBasicItemTemplate() - { - App.WaitForElement(Options); - App.Tap(Options); - App.WaitForElement(ItemTemplateBasic); - App.Tap(ItemTemplateBasic); - App.WaitForElement(Apply); - App.Tap(Apply); - App.WaitForElement("Apple"); - App.WaitForElement("Banana"); - } - + public const string GroupingFeatureMatrix = "CollectionView Feature Matrix"; + public const string Options = "Options"; + public const string Apply = "Apply"; + public const string GroupHeaderTemplateGrid = "GroupHeaderTemplateGrid"; + public const string GroupFooterTemplateGrid = "GroupFooterTemplateGrid"; + public const string IsGroupedTrue = "IsGroupedTrue"; + public const string ItemsSourceGroupedList = "ItemsSourceGroupedList"; + public const string FooterString = "FooterString"; + public const string HeaderString = "HeaderString"; + public const string ItemTemplateBasic = "ItemTemplateBasic"; + public const string ItemsLayoutHorizontalList = "ItemsLayoutHorizontalList"; + public const string ItemsLayoutHorizontalGrid = "ItemsLayoutHorizontalGrid"; + public const string ItemsLayoutVerticalGrid = "ItemsLayoutVerticalGrid"; + + + public CollectionView_GroupingFeatureTests(TestDevice device) + : base(device) + { + } + protected override void FixtureSetup() + { + base.FixtureSetup(); + App.NavigateToGallery(GroupingFeatureMatrix); + } + + [Test, Order(1)] + [Category(UITestCategories.CollectionView)] + public void VerifyGroupFooterTemplate_WithFooterString() + { + App.WaitForElement("GroupingButton"); + App.Tap("GroupingButton"); + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(GroupFooterTemplateGrid); + App.Tap(GroupFooterTemplateGrid); + App.WaitForElement(FooterString); + App.Tap(FooterString); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForElement("CollectionView Footer(String)"); + App.WaitForNoElement("GroupFooterTemplate"); + App.WaitForNoElement("GroupFooterTemplate"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyGroupFooterTemplate_WithHeaderString() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(GroupFooterTemplateGrid); + App.Tap(GroupFooterTemplateGrid); + App.WaitForElement(HeaderString); + App.Tap(HeaderString); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForElement("CollectionView Header(String)"); + App.WaitForNoElement("GroupFooterTemplate"); + App.WaitForNoElement("GroupFooterTemplate"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyGroupFooterTemplate_WithBasicItemTemplate() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(GroupFooterTemplateGrid); + App.Tap(GroupFooterTemplateGrid); + App.WaitForElement(ItemTemplateBasic); + App.Tap(ItemTemplateBasic); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForElement("Apple"); + App.WaitForElement("Banana"); + App.WaitForNoElement("GroupFooterTemplate"); + App.WaitForNoElement("GroupFooterTemplate"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyGroupHeaderTemplate_WithFooterString() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(GroupHeaderTemplateGrid); + App.Tap(GroupHeaderTemplateGrid); + App.WaitForElement(FooterString); + App.Tap(FooterString); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForElement("CollectionView Footer(String)"); + App.WaitForNoElement("GroupHeaderTemplate"); + App.WaitForNoElement("GroupHeaderTemplate"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyGroupHeaderTemplate_WithHeaderString() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(GroupHeaderTemplateGrid); + App.Tap(GroupHeaderTemplateGrid); + App.WaitForElement(HeaderString); + App.Tap(HeaderString); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForElement("CollectionView Header(String)"); + App.WaitForNoElement("GroupHeaderTemplate"); + App.WaitForNoElement("GroupHeaderTemplate"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyGroupHeaderTemplate_WithBasicItemTemplate() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(GroupHeaderTemplateGrid); + App.Tap(GroupHeaderTemplateGrid); + App.WaitForElement(ItemTemplateBasic); + App.Tap(ItemTemplateBasic); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForElement("Apple"); + App.WaitForElement("Banana"); + App.WaitForNoElement("GroupHeaderTemplate"); + App.WaitForNoElement("GroupHeaderTemplate"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyGroupHeaderAndFooterTemplate_WithObservableCollection() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(GroupHeaderTemplateGrid); + App.Tap(GroupHeaderTemplateGrid); + App.WaitForElement(GroupFooterTemplateGrid); + App.Tap(GroupFooterTemplateGrid); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForNoElement("GroupHeaderTemplate"); + App.WaitForNoElement("GroupHeaderTemplate"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyGroupHeaderAndFooterTemplate_WithItemSourceNull() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(GroupHeaderTemplateGrid); + App.Tap(GroupHeaderTemplateGrid); + App.WaitForElement(GroupFooterTemplateGrid); + App.Tap(GroupFooterTemplateGrid); + App.WaitForElement("ItemsSourceNone"); + App.Tap("ItemsSourceNone"); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForNoElement("GroupHeaderTemplate"); + App.WaitForNoElement("GroupFooterTemplate"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyIsGroupedFalse_WithItemSourceObservableCollection() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForElement("Apple"); + App.WaitForElement("Banana"); + App.WaitForNoElement("Fruits"); + App.WaitForNoElement("Vegetables"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyIsGroupedFalse_WithHeaderAndFooterString() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(HeaderString); + App.Tap(HeaderString); + App.WaitForElement(FooterString); + App.Tap(FooterString); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForElement("CollectionView Header(String)"); + App.WaitForElement("CollectionView Footer(String)"); + } + + [Test] + [Category(UITestCategories.CollectionView)] + public void VerifyIsGroupedFalse_WithBasicItemTemplate() + { + App.WaitForElement(Options); + App.Tap(Options); + App.WaitForElement(ItemTemplateBasic); + App.Tap(ItemTemplateBasic); + App.WaitForElement(Apply); + App.Tap(Apply); + App.WaitForElement("Apple"); + App.WaitForElement("Banana"); + } + #if TEST_FAILS_ON_WINDOWS // [Windows] NullReferenceException thrown When Toggling IsGrouped to True in ObservableCollection Binding Issue Link: https://github.com/dotnet/maui/issues/28824 [Test] [Category(UITestCategories.CollectionView)] diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/StepperFeatureTests.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/StepperFeatureTests.cs index 20f23edbba98..e8e7fbf56feb 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/StepperFeatureTests.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/StepperFeatureTests.cs @@ -7,102 +7,102 @@ namespace Microsoft.Maui.TestCases.Tests; [Category(UITestCategories.Stepper)] public class StepperFeatureTests : UITest { - public const string StepperFeatureMatrix = "Stepper Feature Matrix"; - - public StepperFeatureTests(TestDevice device) - : base(device) - { - } - - protected override void FixtureSetup() - { - base.FixtureSetup(); - App.NavigateToGallery(StepperFeatureMatrix); - } - - [Test, Order(1)] - public void Stepper_ValidateDefaultValues_VerifyLabels() - { - App.WaitForElement("Options"); - Assert.That(App.FindElement("MinimumLabel").GetText(), Is.EqualTo("0.00")); - Assert.That(App.FindElement("MaximumLabel").GetText(), Is.EqualTo("10.00")); - Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("0.00")); - } - - [Test] - public void Stepper_SetMinimumValue_VerifyMinimumLabel() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("MinimumEntry"); - App.EnterText("MinimumEntry", "2"); - App.PressEnter(); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - Assert.That(App.FindElement("MinimumLabel").GetText(), Is.EqualTo("2.00")); - } - - [Test] - public void Stepper_SetMaximumValue_VerifyMaximumLabel() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("MaximumEntry"); - App.EnterText("MaximumEntry", "20"); - App.PressEnter(); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - Assert.That(App.FindElement("MaximumLabel").GetText(), Is.EqualTo("20.00")); - } - - [Test] - public void Stepper_SetValueWithinRange_VerifyValueLabel() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("ValueEntry"); - App.EnterText("ValueEntry", "5"); - App.PressEnter(); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("5.00")); - } - - [Test] - public void Stepper_SetIncrementValue_VerifyIncrement() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("IncrementEntry"); - App.EnterText("IncrementEntry", "2"); - App.PressEnter(); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - App.IncreaseStepper("StepperControl"); - Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("2.00")); - } - - [Test] - public void Stepper_SetValueExceedsMaximum() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("MaximumEntry"); - App.ClearText("MaximumEntry"); - App.EnterText("MaximumEntry", "100"); - App.PressEnter(); - App.ClearText("ValueEntry"); - App.EnterText("ValueEntry", "200"); - App.PressEnter(); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("100.00")); - } + public const string StepperFeatureMatrix = "Stepper Feature Matrix"; + + public StepperFeatureTests(TestDevice device) + : base(device) + { + } + + protected override void FixtureSetup() + { + base.FixtureSetup(); + App.NavigateToGallery(StepperFeatureMatrix); + } + + [Test, Order(1)] + public void Stepper_ValidateDefaultValues_VerifyLabels() + { + App.WaitForElement("Options"); + Assert.That(App.FindElement("MinimumLabel").GetText(), Is.EqualTo("0.00")); + Assert.That(App.FindElement("MaximumLabel").GetText(), Is.EqualTo("10.00")); + Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("0.00")); + } + + [Test] + public void Stepper_SetMinimumValue_VerifyMinimumLabel() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("MinimumEntry"); + App.EnterText("MinimumEntry", "2"); + App.PressEnter(); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + Assert.That(App.FindElement("MinimumLabel").GetText(), Is.EqualTo("2.00")); + } + + [Test] + public void Stepper_SetMaximumValue_VerifyMaximumLabel() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("MaximumEntry"); + App.EnterText("MaximumEntry", "20"); + App.PressEnter(); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + Assert.That(App.FindElement("MaximumLabel").GetText(), Is.EqualTo("20.00")); + } + + [Test] + public void Stepper_SetValueWithinRange_VerifyValueLabel() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("ValueEntry"); + App.EnterText("ValueEntry", "5"); + App.PressEnter(); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("5.00")); + } + + [Test] + public void Stepper_SetIncrementValue_VerifyIncrement() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("IncrementEntry"); + App.EnterText("IncrementEntry", "2"); + App.PressEnter(); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + App.IncreaseStepper("StepperControl"); + Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("2.00")); + } + + [Test] + public void Stepper_SetValueExceedsMaximum() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("MaximumEntry"); + App.ClearText("MaximumEntry"); + App.EnterText("MaximumEntry", "100"); + App.PressEnter(); + App.ClearText("ValueEntry"); + App.EnterText("ValueEntry", "200"); + App.PressEnter(); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("100.00")); + } #if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_IOS && TEST_FAILS_ON_WINDOWS // Related Issue Link : https://github.com/dotnet/maui/issues/12243 @@ -144,205 +144,205 @@ public void Stepper_MinimumExceedsMaximum_SetsMinimumToMaximum() } #endif - [Test] - public void Stepper_SetEnabledStateToFalse_VerifyVisualState() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("IsEnabledFalseRadio"); - App.Tap("IsEnabledFalseRadio"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - App.IncreaseStepper("StepperControl"); - Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("0.00")); - } - - [Test] - public void Stepper_SetVisibilityToFalse_VerifyVisualState() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("IsVisibleFalseRadio"); - App.Tap("IsVisibleFalseRadio"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - App.WaitForNoElement("StepperControl"); - } + [Test] + public void Stepper_SetEnabledStateToFalse_VerifyVisualState() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("IsEnabledFalseRadio"); + App.Tap("IsEnabledFalseRadio"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + App.IncreaseStepper("StepperControl"); + Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("0.00")); + } + + [Test] + public void Stepper_SetVisibilityToFalse_VerifyVisualState() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("IsVisibleFalseRadio"); + App.Tap("IsVisibleFalseRadio"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + App.WaitForNoElement("StepperControl"); + } #if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //Related Issue Link : https://github.com/dotnet/maui/issues/29704 - [Test] - public void Stepper_ChangeFlowDirection_RTL_VerifyVisualState() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("FlowDirectionRTLRadio"); - App.Tap("FlowDirectionRTLRadio"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - VerifyScreenshot(); - } + [Test] + public void Stepper_ChangeFlowDirection_RTL_VerifyVisualState() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("FlowDirectionRTLRadio"); + App.Tap("FlowDirectionRTLRadio"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + VerifyScreenshot(); + } #endif - [Test] - public void Stepper_AtMinimumValue_DecrementButtonDisabled() - { - App.WaitForElement("Options"); - App.Tap("Options"); - - App.WaitForElement("MinimumEntry"); - App.ClearText("MinimumEntry"); - App.EnterText("MinimumEntry", "10"); - App.PressEnter(); - - App.WaitForElement("ValueEntry"); - App.ClearText("ValueEntry"); - App.EnterText("ValueEntry", "10"); - App.PressEnter(); - - App.WaitForElement("Apply"); - App.Tap("Apply"); - - App.WaitForElement("Options"); - - var currentValue = App.FindElement("ValueLabel").GetText(); - Assert.That(currentValue, Is.EqualTo("10.00")); - - App.DecreaseStepper("StepperControl"); - - var newValue = App.FindElement("ValueLabel").GetText(); - Assert.That(newValue, Is.EqualTo("10.00")); - } - - [Test] - public void Stepper_AtMaximumValue_IncrementButtonDisabled() - { - App.WaitForElement("Options"); - App.Tap("Options"); - - App.WaitForElement("MaximumEntry"); - App.EnterText("MaximumEntry", "10"); - App.PressEnter(); - - App.WaitForElement("ValueEntry"); - App.EnterText("ValueEntry", "10"); - App.PressEnter(); - - App.WaitForElement("Apply"); - App.Tap("Apply"); - - App.WaitForElement("Options"); - - var currentValue = App.FindElement("ValueLabel").GetText(); - Assert.That(currentValue, Is.EqualTo("10.00")); - - App.IncreaseStepper("StepperControl"); - - var newValue = App.FindElement("ValueLabel").GetText(); - Assert.That(newValue, Is.EqualTo("10.00")); - } - - [Test] - public void Stepper_SetIncrementAndVerifyValueChange() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("IncrementEntry"); - App.EnterText("IncrementEntry", "5"); - App.PressEnter(); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - App.IncreaseStepper("StepperControl"); - Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("5.00")); - App.IncreaseStepper("StepperControl"); - Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("10.00")); - } - - - [Test] - public void Stepper_ResetToInitialState_VerifyDefaultValues() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("MinimumEntry"); - App.EnterText("MinimumEntry", "10"); - App.PressEnter(); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("Options"); - Assert.That(App.FindElement("MinimumLabel").GetText(), Is.EqualTo("0.00")); - Assert.That(App.FindElement("MaximumLabel").GetText(), Is.EqualTo("10.00")); - Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("0.00")); - } + [Test] + public void Stepper_AtMinimumValue_DecrementButtonDisabled() + { + App.WaitForElement("Options"); + App.Tap("Options"); + + App.WaitForElement("MinimumEntry"); + App.ClearText("MinimumEntry"); + App.EnterText("MinimumEntry", "10"); + App.PressEnter(); + + App.WaitForElement("ValueEntry"); + App.ClearText("ValueEntry"); + App.EnterText("ValueEntry", "10"); + App.PressEnter(); + + App.WaitForElement("Apply"); + App.Tap("Apply"); + + App.WaitForElement("Options"); + + var currentValue = App.FindElement("ValueLabel").GetText(); + Assert.That(currentValue, Is.EqualTo("10.00")); + + App.DecreaseStepper("StepperControl"); + + var newValue = App.FindElement("ValueLabel").GetText(); + Assert.That(newValue, Is.EqualTo("10.00")); + } + + [Test] + public void Stepper_AtMaximumValue_IncrementButtonDisabled() + { + App.WaitForElement("Options"); + App.Tap("Options"); + + App.WaitForElement("MaximumEntry"); + App.EnterText("MaximumEntry", "10"); + App.PressEnter(); + + App.WaitForElement("ValueEntry"); + App.EnterText("ValueEntry", "10"); + App.PressEnter(); + + App.WaitForElement("Apply"); + App.Tap("Apply"); + + App.WaitForElement("Options"); + + var currentValue = App.FindElement("ValueLabel").GetText(); + Assert.That(currentValue, Is.EqualTo("10.00")); + + App.IncreaseStepper("StepperControl"); + + var newValue = App.FindElement("ValueLabel").GetText(); + Assert.That(newValue, Is.EqualTo("10.00")); + } + + [Test] + public void Stepper_SetIncrementAndVerifyValueChange() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("IncrementEntry"); + App.EnterText("IncrementEntry", "5"); + App.PressEnter(); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + App.IncreaseStepper("StepperControl"); + Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("5.00")); + App.IncreaseStepper("StepperControl"); + Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("10.00")); + } + + + [Test] + public void Stepper_ResetToInitialState_VerifyDefaultValues() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("MinimumEntry"); + App.EnterText("MinimumEntry", "10"); + App.PressEnter(); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("Options"); + Assert.That(App.FindElement("MinimumLabel").GetText(), Is.EqualTo("0.00")); + Assert.That(App.FindElement("MaximumLabel").GetText(), Is.EqualTo("10.00")); + Assert.That(App.FindElement("ValueLabel").GetText(), Is.EqualTo("0.00")); + } #if TEST_FAILS_ON_WINDOWS // Related Issue Link : https://github.com/dotnet/maui/issues/29740 - [Test] - public void Stepper_IncrementDoesNotExceedMaximum() - { - App.WaitForElement("Options"); - App.Tap("Options"); - - App.WaitForElement("MaximumEntry"); - App.ClearText("MaximumEntry"); - App.EnterText("MaximumEntry", "10"); - App.PressEnter(); - - App.WaitForElement("IncrementEntry"); - App.ClearText("IncrementEntry"); - App.EnterText("IncrementEntry", "3"); - App.PressEnter(); - - App.WaitForElement("Apply"); - App.Tap("Apply"); - - App.WaitForElement("Options"); - - App.IncreaseStepper("StepperControl"); - App.IncreaseStepper("StepperControl"); - App.IncreaseStepper("StepperControl"); - App.IncreaseStepper("StepperControl"); - - var currentValue = App.FindElement("ValueLabel").GetText(); - Assert.That(currentValue, Is.EqualTo("10.00")); - } + [Test] + public void Stepper_IncrementDoesNotExceedMaximum() + { + App.WaitForElement("Options"); + App.Tap("Options"); + + App.WaitForElement("MaximumEntry"); + App.ClearText("MaximumEntry"); + App.EnterText("MaximumEntry", "10"); + App.PressEnter(); + + App.WaitForElement("IncrementEntry"); + App.ClearText("IncrementEntry"); + App.EnterText("IncrementEntry", "3"); + App.PressEnter(); + + App.WaitForElement("Apply"); + App.Tap("Apply"); + + App.WaitForElement("Options"); + + App.IncreaseStepper("StepperControl"); + App.IncreaseStepper("StepperControl"); + App.IncreaseStepper("StepperControl"); + App.IncreaseStepper("StepperControl"); + + var currentValue = App.FindElement("ValueLabel").GetText(); + Assert.That(currentValue, Is.EqualTo("10.00")); + } #endif - [Test] - public void Stepper_DecrementDoesNotGoBelowMinimum() - { - App.WaitForElement("Options"); - App.Tap("Options"); + [Test] + public void Stepper_DecrementDoesNotGoBelowMinimum() + { + App.WaitForElement("Options"); + App.Tap("Options"); - App.WaitForElement("MinimumEntry"); - App.ClearText("MinimumEntry"); - App.EnterText("MinimumEntry", "0"); - App.PressEnter(); + App.WaitForElement("MinimumEntry"); + App.ClearText("MinimumEntry"); + App.EnterText("MinimumEntry", "0"); + App.PressEnter(); - App.WaitForElement("IncrementEntry"); - App.ClearText("IncrementEntry"); - App.EnterText("IncrementEntry", "2"); - App.PressEnter(); + App.WaitForElement("IncrementEntry"); + App.ClearText("IncrementEntry"); + App.EnterText("IncrementEntry", "2"); + App.PressEnter(); - App.WaitForElement("ValueEntry"); - App.ClearText("ValueEntry"); - App.EnterText("ValueEntry", "2"); - App.PressEnter(); + App.WaitForElement("ValueEntry"); + App.ClearText("ValueEntry"); + App.EnterText("ValueEntry", "2"); + App.PressEnter(); - App.WaitForElement("Apply"); - App.Tap("Apply"); + App.WaitForElement("Apply"); + App.Tap("Apply"); - App.WaitForElement("Options"); + App.WaitForElement("Options"); - App.DecreaseStepper("StepperControl"); - App.DecreaseStepper("StepperControl"); + App.DecreaseStepper("StepperControl"); + App.DecreaseStepper("StepperControl"); - var currentValue = App.FindElement("ValueLabel").GetText(); - Assert.That(currentValue, Is.EqualTo("0.00")); - } + var currentValue = App.FindElement("ValueLabel").GetText(); + Assert.That(currentValue, Is.EqualTo("0.00")); + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19197.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19197.cs index 912fc9cc16da..8d4d2a35730c 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19197.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19197.cs @@ -1,4 +1,4 @@ -#if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS +#if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS // Test failing on Android. // The test fails on Windows and MacCatalyst because the SetOrientation method, which is intended to change the device orientation, is only supported on mobile platforms Android and iOS. using NUnit.Framework; diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29609.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29609.cs index 8b5d75f10f29..1733a3b895c2 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29609.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29609.cs @@ -1,4 +1,4 @@ -# if TEST_FAILS_ON_WINDOWS // ItemSpacing on CarouselView is not applied on Windows https://github.com/dotnet/maui/issues/29772 +#if TEST_FAILS_ON_WINDOWS // ItemSpacing on CarouselView is not applied on Windows https://github.com/dotnet/maui/issues/29772 using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -7,18 +7,18 @@ namespace Microsoft.Maui.TestCases.Tests.Issues; public class Issue29609 : _IssuesUITest { - public Issue29609(TestDevice testDevice) : base(testDevice) - { - } + public Issue29609(TestDevice testDevice) : base(testDevice) + { + } - public override string Issue => "ItemSpacing on CarouselView resizes items"; + public override string Issue => "ItemSpacing on CarouselView resizes items"; - [Test] - [Category(UITestCategories.CarouselView)] - public void VerifySpacingAffectsItemSize() - { - App.WaitForElement("29609DescriptionLabel"); - VerifyScreenshot(); - } + [Test] + [Category(UITestCategories.CarouselView)] + public void VerifySpacingAffectsItemSize() + { + App.WaitForElement("29609DescriptionLabel"); + VerifyScreenshot(); + } } #endif \ No newline at end of file diff --git a/src/Core/src/Handlers/Window/WindowHandler.iOS.cs b/src/Core/src/Handlers/Window/WindowHandler.iOS.cs index c60562cb30c3..643866ee7d9f 100644 --- a/src/Core/src/Handlers/Window/WindowHandler.iOS.cs +++ b/src/Core/src/Handlers/Window/WindowHandler.iOS.cs @@ -14,7 +14,7 @@ protected override void ConnectHandler(UIWindow platformView) base.ConnectHandler(platformView); _frameObserverProxy.Connect(VirtualView, platformView); - + // For newer Mac Catalyst versions, we want to wait until we get effective window dimensions from the platform. if (OperatingSystem.IsMacCatalystVersionAtLeast(16)) { @@ -171,7 +171,7 @@ void HandleEffectiveGeometryObserved(NSObservedChange obj) } } } - + class FrameObserverProxy { WeakReference? _virtualView;