forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayoutRenderer.cs
75 lines (63 loc) · 1.77 KB
/
LayoutRenderer.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
69
70
71
72
73
74
75
using System.ComponentModel;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Media;
namespace Xamarin.Forms.Platform.UWP
{
public class LayoutRenderer : ViewRenderer<Layout, FrameworkElement>
{
protected override void OnElementChanged(ElementChangedEventArgs<Layout> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
SizeChanged -= OnSizeChanged;
SetAutomationId(null);
}
if (e.NewElement != null)
{
SizeChanged += OnSizeChanged;
UpdateClipToBounds();
if (!string.IsNullOrEmpty(Element.AutomationId))
{
SetAutomationId(Element.AutomationId);
}
}
}
protected override void UpdateBackgroundColor()
{
base.UpdateBackgroundColor();
if (GetValue(BackgroundProperty) == null && Children.Count == 0)
{
// Forces the layout to take up actual space if it's otherwise empty
Background = new SolidColorBrush(Colors.Transparent);
}
}
protected override AutomationPeer OnCreateAutomationPeer()
{
// Since layouts in Forms can be interacted with, we need to create automation peers
// for them so we can interact with them in automated tests
return new FrameworkElementAutomationPeer(this);
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == Layout.IsClippedToBoundsProperty.PropertyName)
UpdateClipToBounds();
}
void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
UpdateClipToBounds();
}
void UpdateClipToBounds()
{
Clip = null;
if (Element.IsClippedToBounds)
{
Clip = new RectangleGeometry { Rect = new Rect(0, 0, ActualWidth, ActualHeight) };
}
}
}
}