1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.UI.Shared/Converters/SKColorToStringConverter.cs
SpoinkyNL 8d901027ee Shared UI - Resolved all remaining warnings
UI - Resolved all remaining warnings
Layer properties - Fixed DisableKeyframes layer property attribute not being applied
2020-11-20 23:13:37 +01:00

31 lines
950 B
C#

using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using SkiaSharp;
namespace Artemis.UI.Shared
{
/// <inheritdoc />
/// <summary>
/// Converts <see cref="SKColor" />into <see cref="T:System.String" />.
/// </summary>
[ValueConversion(typeof(Color), typeof(string))]
public class SKColorToStringConverter : IValueConverter
{
/// <inheritdoc />
public object? Convert(object? value, Type targetType, object parameter, CultureInfo culture)
{
return value?.ToString();
}
/// <inheritdoc />
public object ConvertBack(object? value, Type targetType, object parameter, CultureInfo culture)
{
if (string.IsNullOrWhiteSpace(value as string))
return SKColor.Empty;
return SKColor.TryParse((string) value!, out SKColor color) ? color : SKColor.Empty;
}
}
}