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)
if (command != null)
{
var commandParameter = colView.SelectionChangedCommandParameter;
+ if (commandParameter == null)
+ {
+ commandParameter = args;
+ }
if (command.CanExecute(commandParameter))
{
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
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)
set
{
_name = value;
- OnPropertyChanged("Name");
+ OnPropertyChanged();
}
}
set
{
_scientificName = value;
- OnPropertyChanged("ScientificName");
+ OnPropertyChanged();
}
}
}
-public class Animals
+public class Animals : INotifyPropertyChanged
{
(string Name,string ScientificName)[] namePool = {
("Bald Eagle", "Haliaeetus leucocephalus"),
("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<Animal> Source {get; private set; } = new ObservableCollection<Animal>();
public Animals()
{
for (int i = 0; i < namePool.Length; i++)
Source.Add(new Animal(namePool[i].Name, namePool[i].ScientificName));
+
+ SelectedAnimalChangedCommand = new Command<SelectionChangedEventArgs>((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<SelectionChangedEventArgs> SelectedAnimalChangedCommand { get; }
}