1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . ComponentModel ;
3
4
using System . Diagnostics ;
4
5
using System . Linq ;
6
+ using System . Runtime . CompilerServices ;
5
7
using System . Text ;
6
8
using System . Threading . Tasks ;
9
+ using System . Windows ;
7
10
using System . Windows . Input ;
8
11
using MaterialDesignColors . WpfExample . Domain ;
9
12
using MaterialDesignThemes . Wpf ;
10
13
11
14
namespace MaterialDesignDemo
12
15
{
13
- public class IconPackViewModel
16
+ public class IconPackViewModel : INotifyPropertyChanged
14
17
{
15
18
private readonly Lazy < IEnumerable < PackIconKind > > _packIconKinds ;
16
19
17
20
public IconPackViewModel ( )
18
21
{
19
22
OpenDotComCommand = new AnotherCommandImplementation ( OpenDotCom ) ;
23
+ SearchCommand = new AnotherCommandImplementation ( Search ) ;
24
+ CopyToClipboardCommand = new AnotherCommandImplementation ( CopyToClipboard ) ;
20
25
_packIconKinds = new Lazy < IEnumerable < PackIconKind > > ( ( ) =>
21
26
Enum . GetValues ( typeof ( PackIconKind ) ) . OfType < PackIconKind > ( )
22
27
. OrderBy ( k => k . ToString ( ) , StringComparer . InvariantCultureIgnoreCase ) . ToList ( )
@@ -25,14 +30,47 @@ public IconPackViewModel()
25
30
}
26
31
27
32
public ICommand OpenDotComCommand { get ; }
33
+ public ICommand SearchCommand { get ; }
34
+ public ICommand CopyToClipboardCommand { get ; }
28
35
29
- public IEnumerable < PackIconKind > Kinds => _packIconKinds . Value ;
36
+ private IEnumerable < PackIconKind > _kinds ;
37
+ public IEnumerable < PackIconKind > Kinds
38
+ {
39
+ get { return _kinds ?? ( _kinds = _packIconKinds . Value ) ; }
40
+ set
41
+ {
42
+ _kinds = value ;
43
+ OnPropertyChanged ( ) ;
44
+ }
45
+ }
30
46
31
47
private void OpenDotCom ( object obj )
32
48
{
33
49
Process . Start ( "https://materialdesignicons.com/" ) ;
34
50
}
35
51
52
+ private void Search ( object obj )
53
+ {
54
+ var text = obj as string ;
55
+ if ( string . IsNullOrWhiteSpace ( text ) )
56
+ Kinds = _packIconKinds . Value ;
57
+ else
58
+ Kinds =
59
+ _packIconKinds . Value . Where (
60
+ x => x . ToString ( ) . IndexOf ( text , StringComparison . CurrentCultureIgnoreCase ) >= 0 ) ;
61
+ }
62
+
63
+ private void CopyToClipboard ( object obj )
64
+ {
65
+ var kind = ( PackIconKind ? ) obj ;
66
+ Clipboard . SetText ( $ "<materialDesign:PackIcon Kind=\" { kind } \" />") ;
67
+ }
68
+
69
+ public event PropertyChangedEventHandler PropertyChanged ;
36
70
71
+ protected virtual void OnPropertyChanged ( [ CallerMemberName ] string propertyName = null )
72
+ {
73
+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
74
+ }
37
75
}
38
76
}
0 commit comments