forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrushHelpers.cs
43 lines (37 loc) · 1007 Bytes
/
BrushHelpers.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
using System;
using Windows.UI.Xaml.Media;
#if WINDOWS_UWP
namespace Xamarin.Forms.Platform.UWP
#else
namespace Xamarin.Forms.Platform.WinRT
#endif
{
internal static class BrushHelpers
{
/// <summary>
/// Handles the logic for setting a Xamarin.Forms Color for a Brush
/// while caching the original default brush
/// </summary>
/// <param name="color">The target Xamarin.Forms.Color</param>
/// <param name="defaultbrush">The renderer's cache for the default brush</param>
/// <param name="getter">Delegate for retrieving the Control's current Brush</param>
/// <param name="setter">Delegate for setting the Control's Brush</param>
public static void UpdateColor(Color color, ref Brush defaultbrush, Func<Brush> getter, Action<Brush> setter)
{
if (color.IsDefault)
{
if (defaultbrush == null)
{
return;
}
setter(defaultbrush);
return;
}
if (defaultbrush == null)
{
defaultbrush = getter();
}
setter(color.ToBrush());
}
}
}