mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Modules - Added option to disable updates while activation is overridden Display conditions - Added SKColor support Data bindings - Added SKColor support
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
using System.Windows.Media;
|
|
|
|
namespace Artemis.UI.Shared
|
|
{
|
|
/// <inheritdoc />
|
|
/// <summary>
|
|
/// Converts <see cref="T:System.Windows.Media.Color" /> into <see cref="T:System.String" />.
|
|
/// </summary>
|
|
[ValueConversion(typeof(Color), typeof(string))]
|
|
public class ColorToStringConverter : IValueConverter
|
|
{
|
|
/// <inheritdoc />
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return value?.ToString()?.ToUpper();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrWhiteSpace((string) value))
|
|
return default(Color);
|
|
|
|
var color = ColorConverter.ConvertFromString((string) value);
|
|
if (color is Color c)
|
|
return c;
|
|
|
|
return default(Color);
|
|
}
|
|
catch (FormatException)
|
|
{
|
|
return default(Color);
|
|
}
|
|
}
|
|
}
|
|
} |