Skip to content

Commit bd5c8d9

Browse files
committed
Make up comboboxtemplate
1 parent b63966d commit bd5c8d9

File tree

4 files changed

+294
-87
lines changed

4 files changed

+294
-87
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Data;
8+
9+
namespace MaterialDesignThemes.Wpf.Converters
10+
{
11+
public enum MathOperation
12+
{
13+
Add,
14+
Sub,
15+
Multiply,
16+
Divide
17+
}
18+
19+
public sealed class MathConverter : IValueConverter
20+
{
21+
public MathOperation Operation { get; set; }
22+
23+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
24+
{
25+
if (value is int)
26+
{
27+
switch (Operation)
28+
{
29+
default:
30+
case MathOperation.Add:
31+
return (int)value + System.Convert.ToInt32(parameter);
32+
case MathOperation.Divide:
33+
return (int)value / System.Convert.ToInt32(parameter);
34+
case MathOperation.Multiply:
35+
return (int)value * System.Convert.ToInt32(parameter);
36+
case MathOperation.Sub:
37+
return (int)value + System.Convert.ToInt32(parameter);
38+
}
39+
}
40+
41+
if (value is double)
42+
{
43+
switch (Operation)
44+
{
45+
default:
46+
case MathOperation.Add:
47+
return (double)value + System.Convert.ToDouble(parameter);
48+
case MathOperation.Divide:
49+
return (double)value / System.Convert.ToDouble(parameter);
50+
case MathOperation.Multiply:
51+
return (double)value * System.Convert.ToDouble(parameter);
52+
case MathOperation.Sub:
53+
return (double)value + System.Convert.ToDouble(parameter);
54+
}
55+
}
56+
57+
return Binding.DoNothing;
58+
}
59+
60+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
61+
{
62+
return Binding.DoNothing;
63+
}
64+
}
65+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows.Data;
9+
10+
namespace MaterialDesignThemes.Wpf.Converters
11+
{
12+
public sealed class MathMultipleConverter : IMultiValueConverter
13+
{
14+
public MathOperation Operation { get; set; }
15+
16+
public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
17+
{
18+
double value1, value2;
19+
if (Double.TryParse(value[0].ToString(), out value1) && Double.TryParse(value[1].ToString(), out value2))
20+
{
21+
Debug.WriteLine($"value1: {value1} value2: {value2}");
22+
switch (Operation)
23+
{
24+
default:
25+
case MathOperation.Add:
26+
return value1 + value2;
27+
case MathOperation.Divide:
28+
return value1 / value2;
29+
case MathOperation.Multiply:
30+
return value1 * value2;
31+
case MathOperation.Sub:
32+
return value1 - value2;
33+
}
34+
}
35+
36+
return Binding.DoNothing;
37+
}
38+
39+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
40+
{
41+
throw new NotImplementedException();
42+
}
43+
}
44+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@
216216
<Compile Include="Converters\ClockItemIsCheckedConverter.cs" />
217217
<Compile Include="Converters\ClockLineConverter.cs" />
218218
<Compile Include="Converters\DrawerOffsetConverter.cs" />
219+
<Compile Include="Converters\MathConverter.cs" />
220+
<Compile Include="Converters\MathMultipleConverter.cs" />
219221
<Compile Include="Converters\NotConverter.cs" />
220222
<Compile Include="Converters\NotNullToVisibilityConverter.cs" />
221223
<Compile Include="Converters\NotZeroToVisibilityConverter.cs" />

0 commit comments

Comments
 (0)