forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasterBackgroundConverter.cs
68 lines (56 loc) · 1.62 KB
/
MasterBackgroundConverter.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace Xamarin.Forms.Platform.UWP
{
public class MasterBackgroundConverter : Windows.UI.Xaml.Data.IValueConverter
{
// Obtained by comparing the Mail apps master section background to the detail background
const double Shift = 0.03;
public object Convert(object value, Type targetType, object parameter, string language)
{
SolidColorBrush brush = null;
var element = value as FrameworkElement;
if (element != null)
{
while (brush == null && element != null)
{
DependencyProperty property = GetBackgroundProperty(element);
if (property != null)
{
value = element.GetValue(property);
brush = value as SolidColorBrush;
if (brush != null && brush.Color == Colors.Transparent)
brush = null;
}
element = VisualTreeHelper.GetParent(element) as FrameworkElement;
}
}
brush = value as SolidColorBrush;
if (brush != null)
{
Color color = brush.ToFormsColor();
double delta = Shift;
if (color.Luminosity > .6)
delta = -Shift;
color = color.AddLuminosity(delta);
return new SolidColorBrush(color.ToWindowsColor());
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
static DependencyProperty GetBackgroundProperty(FrameworkElement element)
{
if (element is Control)
return Control.BackgroundProperty;
if (element is Panel)
return Panel.BackgroundProperty;
return null;
}
}
}