/
SplatColorExtensions.cs
47 lines (43 loc) · 1.78 KB
/
SplatColorExtensions.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>
/// Extension methods associated with the <see cref="SplatColor"/> struct.
/// </summary>
public static class SplatColorExtensions
{
/// <summary>
/// Converts a <see cref="SplatColor"/> into the XAML <see cref="Color"/>.
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="Color"/> generated.</returns>
public static Color ToNative(this SplatColor value)
{
return Color.FromArgb(value.A, value.R, value.G, value.B);
}
/// <summary>
/// Converts a <see cref="SplatColor"/> into the XAML <see cref="SolidColorBrush"/>.
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="SolidColorBrush"/> generated.</returns>
public static SolidColorBrush ToNativeBrush(this SplatColor value)
{
var ret = new SolidColorBrush(value.ToNative());
ret.Freeze();
return ret;
}
/// <summary>
/// Converts a <see cref="Color"/> into the XAML <see cref="SplatColor"/>.
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="SplatColor"/> generated.</returns>
public static SplatColor FromNative(this Color value)
{
return SplatColor.FromArgb(value.A, value.R, value.G, value.B);
}
}
}