@@ -12,32 +12,23 @@ public class QuerySuggestionBoxConverter : IMultiValueConverter
12
12
{
13
13
public object Convert ( object [ ] values , Type targetType , object parameter , CultureInfo culture )
14
14
{
15
- if ( values . Length != 3 )
16
- {
17
- return string . Empty ;
18
- }
19
- var QueryTextBox = values [ 0 ] as TextBox ;
20
-
21
- var queryText = ( string ) values [ 2 ] ;
22
-
23
- if ( string . IsNullOrEmpty ( queryText ) )
24
- return string . Empty ;
25
-
26
- // second prop is the current selected item result
27
- var val = values [ 1 ] ;
28
- if ( val == null )
29
- {
15
+ // values[0] is TextBox: The textbox displaying the autocomplete suggestion
16
+ // values[1] is ResultViewModel: Currently selected item in the list
17
+ // values[2] is string: Query text
18
+ if (
19
+ values . Length != 3 ||
20
+ values [ 0 ] is not TextBox queryTextBox ||
21
+ values [ 1 ] is null ||
22
+ values [ 2 ] is not string queryText ||
23
+ string . IsNullOrEmpty ( queryText )
24
+ )
30
25
return string . Empty ;
31
- }
32
- if ( ! ( val is ResultViewModel ) )
33
- {
34
- return System . Windows . Data . Binding . DoNothing ;
35
- }
26
+
27
+ if ( values [ 1 ] is not ResultViewModel selectedItem )
28
+ return Binding . DoNothing ;
36
29
37
30
try
38
31
{
39
- var selectedItem = ( ResultViewModel ) val ;
40
-
41
32
var selectedResult = selectedItem . Result ;
42
33
var selectedResultActionKeyword = string . IsNullOrEmpty ( selectedResult . ActionKeywordAssigned ) ? "" : selectedResult . ActionKeywordAssigned + " " ;
43
34
var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult . Title ;
@@ -50,17 +41,15 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
50
41
// When user typed lower case and result title is uppercase, we still want to display suggestion
51
42
selectedItem . QuerySuggestionText = queryText + selectedResultPossibleSuggestion . Substring ( queryText . Length ) ;
52
43
53
- // Check if Text will be larger then our QueryTextBox
54
- System . Windows . Media . Typeface typeface = new Typeface ( QueryTextBox . FontFamily , QueryTextBox . FontStyle , QueryTextBox . FontWeight , QueryTextBox . FontStretch ) ;
44
+ // Check if Text will be larger than our QueryTextBox
45
+ Typeface typeface = new Typeface ( queryTextBox . FontFamily , queryTextBox . FontStyle , queryTextBox . FontWeight , queryTextBox . FontStretch ) ;
55
46
// TODO: Obsolete warning?
56
- System . Windows . Media . FormattedText ft = new FormattedText ( QueryTextBox . Text , System . Globalization . CultureInfo . DefaultThreadCurrentCulture , System . Windows . FlowDirection . LeftToRight , typeface , QueryTextBox . FontSize , Brushes . Black ) ;
47
+ var ft = new FormattedText ( queryTextBox . Text , CultureInfo . DefaultThreadCurrentCulture , System . Windows . FlowDirection . LeftToRight , typeface , queryTextBox . FontSize , Brushes . Black ) ;
57
48
58
- var offset = QueryTextBox . Padding . Right ;
49
+ var offset = queryTextBox . Padding . Right ;
59
50
60
- if ( ( ft . Width + offset ) > QueryTextBox . ActualWidth || QueryTextBox . HorizontalOffset != 0 )
61
- {
51
+ if ( ft . Width + offset > queryTextBox . ActualWidth || queryTextBox . HorizontalOffset != 0 )
62
52
return string . Empty ;
63
- } ;
64
53
65
54
return selectedItem . QuerySuggestionText ;
66
55
}
0 commit comments