mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Added shared UI library and finished the ColorPicker
This commit is contained in:
1 parent
5e876dc8ca
commit
b9471abdec
30 files changed
+875
-321
No files matched your search
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Artemis.UI.Shared.Converters
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Converts <see cref="T:System.Windows.Media.Color" /> into <see cref="T:System.String" />.
|
||||
/// </summary>
|
||||
[ValueConversion(typeof(Color), typeof(string))]
|
||||
internal class ColorToStringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value?.ToString();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user