Mercurial > silverbladetech
annotate MetroWpf/MetroWpf.Xaml/Converters/AddConverter.cs @ 15:060f02cd4591
Initial commit, pre airport work
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Mon, 12 Mar 2012 23:05:21 +0800 |
parents | |
children |
rev | line source |
---|---|
15
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
1 namespace MetroWpf.Xaml.Converters |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
2 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
3 using System; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
4 using System.Windows; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
5 using System.Windows.Data; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
6 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
7 public class AddConverter : IValueConverter |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
8 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
9 #region IValueConverter Members |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
10 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
11 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
12 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
13 double doubleValue, doubleParameter; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
14 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
15 if (value is string) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
16 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
17 doubleValue = double.Parse((string)value); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
18 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
19 else if (value is double) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
20 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
21 doubleValue = (double)value; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
22 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
23 else if (value is int) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
24 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
25 doubleValue = (int)value; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
26 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
27 else |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
28 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
29 throw new ArgumentException("Unsupported type."); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
30 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
31 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
32 if (parameter is string) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
33 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
34 doubleParameter = double.Parse((string)parameter); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
35 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
36 else if (parameter is double) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
37 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
38 doubleParameter = (double)parameter; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
39 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
40 else if (parameter is int) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
41 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
42 doubleParameter = (int)parameter; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
43 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
44 else |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
45 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
46 throw new ArgumentException("Unsupported type."); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
47 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
48 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
49 return doubleValue + doubleParameter; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
50 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
51 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
52 public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
53 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
54 return null; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
55 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
56 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
57 #endregion |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
58 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
59 } |