/
ColorExtensions.cs
47 lines (43 loc) · 1.88 KB
/
ColorExtensions.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
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System.Windows.Media;
namespace Splat
{
/// <summary>
/// Provides extension methods for interacting with colors, to and from the XAML colors.
/// </summary>
public static class ColorExtensions
{
/// <summary>
/// Converts a <see cref="System.Drawing.Color"/> to a XAML native color.
/// </summary>
/// <param name="value">The System.Drawing.Color to convert.</param>
/// <returns>A native XAML color.</returns>
public static Color ToNative(this System.Drawing.Color value)
{
return Color.FromArgb(value.A, value.R, value.G, value.B);
}
/// <summary>
/// Converts a <see cref="System.Drawing.Color"/> into the cocoa native <see cref="SolidColorBrush"/>.
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="SolidColorBrush"/> generated.</returns>
public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value)
{
var ret = new SolidColorBrush(value.ToNative());
ret.Freeze();
return ret;
}
/// <summary>
/// Converts a <see cref="SolidColorBrush"/> into the XAML <see cref="System.Drawing.Color"/>.
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="System.Drawing.Color"/> generated.</returns>
public static System.Drawing.Color FromNative(this Color value)
{
return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B);
}
}
}