@@ -14,14 +14,14 @@ public class AutoSuggestBox : TextBox
14
14
15
15
#region Dependency Properties
16
16
17
- public IEnumerable Suggestions
17
+ public IEnumerable ? Suggestions
18
18
{
19
19
get => ( IEnumerable ) GetValue ( SuggestionsProperty ) ;
20
20
set => SetValue ( SuggestionsProperty , value ) ;
21
21
}
22
22
23
23
public static readonly DependencyProperty SuggestionsProperty =
24
- DependencyProperty . Register ( " Suggestions" , typeof ( IEnumerable ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( null ) ) ;
24
+ DependencyProperty . Register ( nameof ( Suggestions ) , typeof ( IEnumerable ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( null ) ) ;
25
25
26
26
27
27
public string ValueMember
@@ -30,7 +30,7 @@ public string ValueMember
30
30
set => SetValue ( ValueMemberProperty , value ) ;
31
31
}
32
32
public static readonly DependencyProperty ValueMemberProperty =
33
- DependencyProperty . Register ( " ValueMember" , typeof ( string ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( string ) ) ) ;
33
+ DependencyProperty . Register ( nameof ( ValueMember ) , typeof ( string ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( string ) ) ) ;
34
34
35
35
36
36
public string DisplayMember
@@ -39,47 +39,47 @@ public string DisplayMember
39
39
set => SetValue ( DisplayMemberProperty , value ) ;
40
40
}
41
41
public static readonly DependencyProperty DisplayMemberProperty =
42
- DependencyProperty . Register ( " DisplayMember" , typeof ( string ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( string ) ) ) ;
42
+ DependencyProperty . Register ( nameof ( DisplayMember ) , typeof ( string ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( string ) ) ) ;
43
43
44
44
public Brush DropDownBackground
45
45
{
46
46
get => ( Brush ) GetValue ( DropDownBackgroundProperty ) ;
47
47
set => SetValue ( DropDownBackgroundProperty , value ) ;
48
48
}
49
49
public static readonly DependencyProperty DropDownBackgroundProperty =
50
- DependencyProperty . Register ( " DropDownBackground" , typeof ( Brush ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( Brush ) ) ) ;
50
+ DependencyProperty . Register ( nameof ( DropDownBackground ) , typeof ( Brush ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( Brush ) ) ) ;
51
51
52
52
public DataTemplate ItemTemplate
53
53
{
54
54
get => ( DataTemplate ) GetValue ( ItemTemplateProperty ) ;
55
55
set => SetValue ( ItemTemplateProperty , value ) ;
56
56
}
57
57
public static readonly DependencyProperty ItemTemplateProperty =
58
- DependencyProperty . Register ( " ItemTemplate" , typeof ( DataTemplate ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( DataTemplate ) ) ) ;
58
+ DependencyProperty . Register ( nameof ( ItemTemplate ) , typeof ( DataTemplate ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( DataTemplate ) ) ) ;
59
59
60
60
public Style ItemContainerStyle
61
61
{
62
62
get => ( Style ) GetValue ( ItemContainerStyleProperty ) ;
63
63
set => SetValue ( ItemContainerStyleProperty , value ) ;
64
64
}
65
65
public static readonly DependencyProperty ItemContainerStyleProperty =
66
- DependencyProperty . Register ( " ItemContainerStyle" , typeof ( Style ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( Style ) ) ) ;
66
+ DependencyProperty . Register ( nameof ( ItemContainerStyle ) , typeof ( Style ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( Style ) ) ) ;
67
67
68
68
public Elevation DropDownElevation
69
69
{
70
70
get => ( Elevation ) GetValue ( DropDownElevationProperty ) ;
71
71
set => SetValue ( DropDownElevationProperty , value ) ;
72
72
}
73
73
public static readonly DependencyProperty DropDownElevationProperty =
74
- DependencyProperty . Register ( " DropDownElevation" , typeof ( Elevation ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( Elevation ) ) ) ;
74
+ DependencyProperty . Register ( nameof ( DropDownElevation ) , typeof ( Elevation ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( Elevation ) ) ) ;
75
75
76
76
public double DropDownMaxHeight
77
77
{
78
78
get => ( double ) GetValue ( DropDownMaxHeightProperty ) ;
79
79
set => SetValue ( DropDownMaxHeightProperty , value ) ;
80
80
}
81
81
public static readonly DependencyProperty DropDownMaxHeightProperty =
82
- DependencyProperty . Register ( " DropDownMaxHeight" , typeof ( double ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( 200.0 ) ) ;
82
+ DependencyProperty . Register ( nameof ( DropDownMaxHeight ) , typeof ( double ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( 200.0 ) ) ;
83
83
84
84
85
85
public bool IsSuggestionOpen
@@ -88,15 +88,15 @@ public bool IsSuggestionOpen
88
88
set => SetValue ( IsSuggestionOpenProperty , value ) ;
89
89
}
90
90
public static readonly DependencyProperty IsSuggestionOpenProperty =
91
- DependencyProperty . Register ( " IsSuggestionOpen" , typeof ( bool ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( bool ) ) ) ;
91
+ DependencyProperty . Register ( nameof ( IsSuggestionOpen ) , typeof ( bool ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( bool ) ) ) ;
92
92
93
93
public object SelectedItem
94
94
{
95
95
get => GetValue ( SelectedItemProperty ) ;
96
96
set => SetValue ( SelectedItemProperty , value ) ;
97
97
}
98
98
public static readonly DependencyProperty SelectedItemProperty =
99
- DependencyProperty . Register ( " SelectedItem" , typeof ( object ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( object ) ) ) ;
99
+ DependencyProperty . Register ( nameof ( SelectedItem ) , typeof ( object ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( object ) ) ) ;
100
100
101
101
102
102
public object SelectedValue
@@ -105,15 +105,11 @@ public object SelectedValue
105
105
set => SetValue ( SelectedValueProperty , value ) ;
106
106
}
107
107
public static readonly DependencyProperty SelectedValueProperty =
108
- DependencyProperty . Register ( "SelectedValue" , typeof ( object ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( object ) ) ) ;
109
-
110
-
111
-
112
-
108
+ DependencyProperty . Register ( nameof ( SelectedValue ) , typeof ( object ) , typeof ( AutoSuggestBox ) , new PropertyMetadata ( default ( object ) ) ) ;
113
109
114
110
public static readonly RoutedEvent SuggestionChosenEvent =
115
111
EventManager . RegisterRoutedEvent (
116
- " SuggestionChosen" ,
112
+ nameof ( SuggestionChosen ) ,
117
113
RoutingStrategy . Bubble ,
118
114
typeof ( RoutedPropertyChangedEventHandler < object > ) ,
119
115
typeof ( AutoSuggestBox ) ) ;
@@ -253,7 +249,7 @@ private void CommitValueSelection(object? selectedValue)
253
249
254
250
private void DecrementSelection ( )
255
251
{
256
- if ( _autoSuggestBoxList is null )
252
+ if ( _autoSuggestBoxList is null || Suggestions is null )
257
253
return ;
258
254
ICollectionView collectionView = CollectionViewSource . GetDefaultView ( Suggestions ) ;
259
255
if ( collectionView . IsCurrentBeforeFirst )
@@ -265,7 +261,7 @@ private void DecrementSelection()
265
261
266
262
private void IncrementSelection ( )
267
263
{
268
- if ( _autoSuggestBoxList is null )
264
+ if ( _autoSuggestBoxList is null || Suggestions is null )
269
265
return ;
270
266
ICollectionView collectionView = CollectionViewSource . GetDefaultView ( Suggestions ) ;
271
267
if ( collectionView . IsCurrentAfterLast )
0 commit comments