11using System ;
22using System . Collections . Generic ;
3+ using System . ComponentModel ;
34using System . Diagnostics ;
45using System . Linq ;
6+ using System . Runtime . CompilerServices ;
57using System . Text ;
68using System . Threading . Tasks ;
9+ using System . Windows ;
710using System . Windows . Input ;
811using MaterialDesignColors . WpfExample . Domain ;
912using MaterialDesignThemes . Wpf ;
1013
1114namespace MaterialDesignDemo
1215{
13- public class IconPackViewModel
16+ public class IconPackViewModel : INotifyPropertyChanged
1417 {
1518 private readonly Lazy < IEnumerable < PackIconKind > > _packIconKinds ;
1619
1720 public IconPackViewModel ( )
1821 {
1922 OpenDotComCommand = new AnotherCommandImplementation ( OpenDotCom ) ;
23+ SearchCommand = new AnotherCommandImplementation ( Search ) ;
24+ CopyToClipboardCommand = new AnotherCommandImplementation ( CopyToClipboard ) ;
2025 _packIconKinds = new Lazy < IEnumerable < PackIconKind > > ( ( ) =>
2126 Enum . GetValues ( typeof ( PackIconKind ) ) . OfType < PackIconKind > ( )
2227 . OrderBy ( k => k . ToString ( ) , StringComparer . InvariantCultureIgnoreCase ) . ToList ( )
@@ -25,14 +30,47 @@ public IconPackViewModel()
2530 }
2631
2732 public ICommand OpenDotComCommand { get ; }
33+ public ICommand SearchCommand { get ; }
34+ public ICommand CopyToClipboardCommand { get ; }
2835
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+ }
3046
3147 private void OpenDotCom ( object obj )
3248 {
3349 Process . Start ( "https://materialdesignicons.com/" ) ;
3450 }
3551
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 ;
3670
71+ protected virtual void OnPropertyChanged ( [ CallerMemberName ] string propertyName = null )
72+ {
73+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
74+ }
3775 }
3876}
0 commit comments