-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertIdentifierViewModel.cs
More file actions
46 lines (38 loc) · 1.7 KB
/
InsertIdentifierViewModel.cs
File metadata and controls
46 lines (38 loc) · 1.7 KB
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
using System.Collections.ObjectModel;
using System.ComponentModel;
using Upsilon.Apps.Passkey.GUI.WPF.Helper;
namespace Upsilon.Apps.Passkey.GUI.WPF.ViewModels
{
internal class InsertIdentifierViewModel(IEnumerable<string> identifiers, string identifier) : INotifyPropertyChanged
{
private readonly string[] _identifiers = [.. identifiers];
public ObservableCollection<string> Identifiers = [.. identifiers.Where(x => x.StartsWith(identifier.Trim(), StringComparison.CurrentCultureIgnoreCase)),
.. identifiers.Where(x => x.Contains(identifier.Trim(), StringComparison.CurrentCultureIgnoreCase)
&& !x.StartsWith(identifier.Trim(), StringComparison.CurrentCultureIgnoreCase))];
public string Identifier
{
get => field.Trim();
set
{
PropertyHelper.SetProperty(ref field, value.Trim(), this, PropertyChanged);
_refreshFilter();
}
} = identifier;
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void _refreshFilter()
{
Identifiers.Clear();
string[] identifiers = [.. _identifiers.Where(x => x.StartsWith(Identifier, StringComparison.CurrentCultureIgnoreCase)),
.. _identifiers.Where(x => x.Contains(Identifier, StringComparison.CurrentCultureIgnoreCase)
&& !x.StartsWith(Identifier, StringComparison.CurrentCultureIgnoreCase))];
foreach (string identifier in identifiers)
{
Identifiers.Add(identifier);
}
}
}
}