mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
32 lines
1.0 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|