From a1ac3f94df08303faed23171d5f2caa70474ae35 Mon Sep 17 00:00:00 2001 From: "EverLEEst(SangHyeon Lee)" Date: Mon, 19 Dec 2022 21:54:05 +0900 Subject: [PATCH] [NUI] Pass SelectionChangedEventArgs by default as SelectionChangedCommandParameter. --- .../Controls/RecyclerView/CollectionView.cs | 6 +++- .../CollectionViewTest/AnimalGridPage.xaml | 3 +- .../CollectionViewTest/AnimalListPage.xaml | 3 +- .../Examples/CollectionViewTest/Animals.cs | 39 +++++++++++++++++++--- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs b/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs index 95c41dc..d032345 100755 --- a/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs +++ b/src/Tizen.NUI.Components/Controls/RecyclerView/CollectionView.cs @@ -47,8 +47,8 @@ namespace Tizen.NUI.Components oldValue = colView.selectedItem; colView.selectedItem = newValue; - var args = new SelectionChangedEventArgs(oldValue, newValue); + var args = new SelectionChangedEventArgs(oldValue, newValue); foreach (RecyclerViewItem item in colView.ContentContainer.Children.Where((item) => item is RecyclerViewItem)) { if (item.BindingContext == null) @@ -1234,6 +1234,10 @@ namespace Tizen.NUI.Components if (command != null) { var commandParameter = colView.SelectionChangedCommandParameter; + if (commandParameter == null) + { + commandParameter = args; + } if (command.CanExecute(commandParameter)) { diff --git a/test/NUITizenGallery/Examples/CollectionViewTest/AnimalGridPage.xaml b/test/NUITizenGallery/Examples/CollectionViewTest/AnimalGridPage.xaml index 3a065f7..f001afe 100755 --- a/test/NUITizenGallery/Examples/CollectionViewTest/AnimalGridPage.xaml +++ b/test/NUITizenGallery/Examples/CollectionViewTest/AnimalGridPage.xaml @@ -26,7 +26,8 @@ ScrollingDirection="Vertical" ItemsSource="{Binding Source}" HideScrollbar="true" - SelectionMode="None"> + SelectionMode="SingleAlways" + SelectionChangedCommand="{Binding SelectedAnimalChangedCommand}"> diff --git a/test/NUITizenGallery/Examples/CollectionViewTest/AnimalListPage.xaml b/test/NUITizenGallery/Examples/CollectionViewTest/AnimalListPage.xaml index b8b0160..84187c8 100755 --- a/test/NUITizenGallery/Examples/CollectionViewTest/AnimalListPage.xaml +++ b/test/NUITizenGallery/Examples/CollectionViewTest/AnimalListPage.xaml @@ -26,7 +26,8 @@ ScrollingDirection="Vertical" ItemsSource="{Binding Source}" HideScrollbar="true" - SelectionMode="None"> + SelectionMode="Single" + SelectionChangedCommand="{Binding SelectedAnimalChangedCommand}"> diff --git a/test/NUITizenGallery/Examples/CollectionViewTest/Animals.cs b/test/NUITizenGallery/Examples/CollectionViewTest/Animals.cs index 14e553a..628ec53 100644 --- a/test/NUITizenGallery/Examples/CollectionViewTest/Animals.cs +++ b/test/NUITizenGallery/Examples/CollectionViewTest/Animals.cs @@ -19,7 +19,9 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Runtime.CompilerServices; using Tizen.NUI; +using Tizen.NUI.Components; using Tizen.NUI.Binding; public class Animal : INotifyPropertyChanged @@ -29,7 +31,7 @@ public class Animal : INotifyPropertyChanged private string _imageUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "/images/animals/"; public event PropertyChangedEventHandler PropertyChanged; - private void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + private void OnPropertyChanged([CallerMemberName] string propertyName="") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public Animal(string name, string scientificName) @@ -44,7 +46,7 @@ public class Animal : INotifyPropertyChanged set { _name = value; - OnPropertyChanged("Name"); + OnPropertyChanged(); } } @@ -54,7 +56,7 @@ public class Animal : INotifyPropertyChanged set { _scientificName = value; - OnPropertyChanged("ScientificName"); + OnPropertyChanged(); } } @@ -70,7 +72,7 @@ public class Animal : INotifyPropertyChanged } -public class Animals +public class Animals : INotifyPropertyChanged { (string Name,string ScientificName)[] namePool = { ("Bald Eagle", "Haliaeetus leucocephalus"), @@ -97,12 +99,39 @@ public class Animals ("Tiger", "Panthera tigris"), ("Wolf", "Canis lupus"), ("Zebra", "Hippotigris"), -}; + }; + + public event PropertyChangedEventHandler PropertyChanged; + private void OnPropertyChanged([CallerMemberName] string propertyName="") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + public ObservableCollection Source {get; private set; } = new ObservableCollection(); public Animals() { for (int i = 0; i < namePool.Length; i++) Source.Add(new Animal(namePool[i].Name, namePool[i].ScientificName)); + + SelectedAnimalChangedCommand = new Command((param) => + { + if (param == null) return; + + Animal animal = null; + // Single Selection Only have 1 or nil object in the list. + foreach (object item in param.PreviousSelection) + { + animal = item as Animal; + if (animal == null) break; + + Console.WriteLine($"Previous selected item {animal.Name}"); + } + foreach (object item in param.CurrentSelection) + { + animal = item as Animal; + if (animal == null) break; + + Console.WriteLine($"Current selected item {animal.Name}"); + } }); } + + public Command SelectedAnimalChangedCommand { get; } } -- 2.7.4