@@ -15,24 +15,25 @@ public sealed class MathMultipleConverter : IMultiValueConverter
15
15
16
16
public object Convert ( object [ ] value , Type targetType , object parameter , CultureInfo culture )
17
17
{
18
+ if ( value == null || value . Length < 2 || value [ 0 ] == null || value [ 1 ] == null ) return Binding . DoNothing ;
19
+
18
20
double value1 , value2 ;
19
- if ( Double . TryParse ( value [ 0 ] . ToString ( ) , out value1 ) && Double . TryParse ( value [ 1 ] . ToString ( ) , out value2 ) )
21
+ if ( ! double . TryParse ( value [ 0 ] . ToString ( ) , out value1 ) || ! double . TryParse ( value [ 1 ] . ToString ( ) , out value2 ) )
22
+ return Binding . DoNothing ;
23
+
24
+ switch ( Operation )
20
25
{
21
- switch ( Operation )
22
- {
23
- default :
24
- case MathOperation . Add :
25
- return value1 + value2 ;
26
- case MathOperation . Divide :
27
- return value1 / value2 ;
28
- case MathOperation . Multiply :
29
- return value1 * value2 ;
30
- case MathOperation . Subtract :
31
- return value1 - value2 ;
32
- }
26
+ default :
27
+ // (case MathOperation.Add:)
28
+ return value1 + value2 ;
29
+ case MathOperation . Divide :
30
+ return value1 / value2 ;
31
+ case MathOperation . Multiply :
32
+ return value1 * value2 ;
33
+ case MathOperation . Subtract :
34
+ return value1 - value2 ;
33
35
}
34
-
35
- return Binding . DoNothing ;
36
+
36
37
}
37
38
38
39
public object [ ] ConvertBack ( object value , Type [ ] targetTypes , object parameter , CultureInfo culture )
0 commit comments