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