-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathBatteryQuarterValueConverter.cs
34 lines (31 loc) · 1.28 KB
/
BatteryQuarterValueConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Globalization;
using System.Windows.Data;
using MahApps.Metro.IconPacks;
namespace IconPacksValueConverterSample
{
[ValueConversion(typeof(double?), typeof(PackIconFontAwesomeKind))]
public sealed class BatteryQuarterValueConverter : IValueConverter
{
/// <summary> Gets the default instance </summary>
public static readonly BatteryQuarterValueConverter Default = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// the value is in this case a double (comes from the Slider)
var percentage = (value as double?).GetValueOrDefault(0);
return percentage switch
{
< 25 => PackIconFontAwesomeKind.BatteryEmptySolid,
< 50 => PackIconFontAwesomeKind.BatteryQuarterSolid,
< 75 => PackIconFontAwesomeKind.BatteryHalfSolid,
< 100 => PackIconFontAwesomeKind.BatteryThreeQuartersSolid,
_ => PackIconFontAwesomeKind.BatteryFullSolid
};
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// nothing here
throw new NotImplementedException();
}
}
}