Files
modernkeepass/WinAppCommon/Converters/DoubleToSolidColorBrushConverter.cs
Geoffroy BONNEVILLE 73670e8689 Create a shared project with all Win App common files (8.1 and 10)
Finally use the dependency injected Resource Service
2020-04-17 16:56:07 +02:00

32 lines
1.0 KiB
C#

using System;
using Windows.UI;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
namespace ModernKeePass.Converters
{
public class DoubleToSolidColorBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
try
{
var currentValue = (double) value;
var maxValue = double.Parse(parameter as string);
var green = System.Convert.ToByte(currentValue / maxValue * byte.MaxValue);
var red = (byte) (byte.MaxValue - green);
return new SolidColorBrush(Color.FromArgb(255, red, green, 0));
}
catch (OverflowException)
{
return new SolidColorBrush(Color.FromArgb(255, 0, byte.MaxValue, 0));
}
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}