-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonkeyViewModel.cs
48 lines (42 loc) · 1.2 KB
/
MonkeyViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace MauiAppSearchBarHandler
{
public partial class MonkeyViewModel : ObservableObject
{
public MonkeyViewModel()
{
SearchText = "Hello";
Search("");
}
public static List<string> MonkeyList = new List<string>()
{
"Golden Snub-Nosed Monkey",
"Mandrill",
"Snow Monkey"
};
[ObservableProperty]
public ObservableCollection<string> searchResult;
[ObservableProperty]
public string searchText;
public void Search(string text)
{
SearchText = text;
if(string.IsNullOrEmpty(text))
{
SearchResult = new ObservableCollection<string>(MonkeyList);
}
else
{
SearchResult = new ObservableCollection<string>(MonkeyList.Where(x => x.Contains(text)).ToList());
}
}
}
}