-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
MvxColorValueConverter.cs
35 lines (28 loc) · 1.26 KB
/
MvxColorValueConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Globalization;
using MvvmCross.Converters;
using MvvmCross.UI;
namespace MvvmCross.Plugin.Color;
public abstract class MvxColorValueConverter : MvxValueConverter
{
private readonly Lazy<IMvxNativeColor?> _nativeColor = new(() => Mvx.IoCProvider?.Resolve<IMvxNativeColor>());
protected abstract System.Drawing.Color Convert(object value, object? parameter, CultureInfo? culture);
public sealed override object Convert(object value, Type? targetType, object? parameter,
CultureInfo? culture)
{
return _nativeColor.Value?.ToNative(Convert(value, parameter, culture)) ?? MvxBindingConstant.UnsetValue;
}
}
public abstract class MvxColorValueConverter<T> : MvxColorValueConverter
{
protected sealed override System.Drawing.Color Convert(object value, object? parameter, CultureInfo? culture)
{
if (value is T t)
return Convert(t, parameter, culture);
return default;
}
protected abstract System.Drawing.Color Convert(T value, object? parameter, CultureInfo? culture);
}