2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Collections.Generic;
20 using System.Collections.ObjectModel;
21 using System.ComponentModel;
22 using System.Runtime.CompilerServices;
24 using Tizen.NUI.Components;
25 using Tizen.NUI.Binding;
27 public class Animal : INotifyPropertyChanged
30 private string _scientificName;
31 private string _imageUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "/images/animals/";
33 public event PropertyChangedEventHandler PropertyChanged;
34 private void OnPropertyChanged([CallerMemberName] string propertyName="") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }
37 public Animal(string name, string scientificName)
40 _scientificName = scientificName;
53 public string ScientificName
55 get => _scientificName;
58 _scientificName = value;
63 public string ImagePath
67 string filename = _name.Replace(" ", "");
68 filename = filename.ToLower() + ".jpg";
69 return _imageUrl + filename;
75 public class Animals : INotifyPropertyChanged
77 (string Name,string ScientificName)[] namePool = {
78 ("Bald Eagle", "Haliaeetus leucocephalus"),
80 ("Cat", "Felis catus"),
81 ("Chicken", "Gallus gallus domesticus"),
82 ("Cow", "Bos taurus"),
84 ("Dog", "Canis lupus familiaris"),
86 ("Elephant", "Elephantidae"),
87 ("Emperor Penguin", "Aptenodytes forsteri"),
88 ("Giraffe", "Giraffa"),
89 ("Horse", "Equus ferus"),
90 ("Leopard", "Panthera pardus"),
91 ("Lion", "Panthera leo"),
92 ("Panda", "Ailuropoda melanoleuca"),
93 ("Peacock", "Pavo cristatus"),
94 ("Pig", "Sus scrofa domesticus"),
95 ("Pigeon", "Columba livia"),
96 ("Red Fox", "Vulpes vulpes"),
97 ("Seagull", "Larus canus"),
98 ("Squirrel", "Sciurus vulgaris"),
99 ("Tiger", "Panthera tigris"),
100 ("Wolf", "Canis lupus"),
101 ("Zebra", "Hippotigris"),
104 public event PropertyChangedEventHandler PropertyChanged;
105 private void OnPropertyChanged([CallerMemberName] string propertyName="") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }
107 public ObservableCollection<Animal> Source {get; private set; } = new ObservableCollection<Animal>();
111 for (int i = 0; i < namePool.Length; i++)
112 Source.Add(new Animal(namePool[i].Name, namePool[i].ScientificName));
114 SelectedAnimalChangedCommand = new Command<SelectionChangedEventArgs>((param) =>
116 if (param == null) return;
118 Animal animal = null;
119 // Single Selection Only have 1 or nil object in the list.
120 foreach (object item in param.PreviousSelection)
122 animal = item as Animal;
123 if (animal == null) break;
125 Console.WriteLine($"Previous selected item {animal.Name}");
127 foreach (object item in param.CurrentSelection)
129 animal = item as Animal;
130 if (animal == null) break;
132 Console.WriteLine($"Current selected item {animal.Name}");
136 public Command<SelectionChangedEventArgs> SelectedAnimalChangedCommand { get; }