summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/ViewRenderer.cs
blob: 3f0d72c589bd555e080bdd3de4a3546309815027 (plain)
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
´╗┐using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using WSize = System.Windows.Size;

namespace Xamarin.Forms.Platform.WinPhone
{
	public class ViewRenderer<TElement, TNativeElement> : VisualElementRenderer<TElement, TNativeElement> where TElement : View where TNativeElement : FrameworkElement
	{
	}

	public class ViewRenderer : ViewRenderer<View, FrameworkElement>
	{
		protected override void OnElementChanged(ElementChangedEventArgs<View> e)
		{
			base.OnElementChanged(e);
			SizeChanged += (sender, args) => UpdateClipToBounds();

			UpdateBackgroundColor();
		}

		protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			base.OnElementPropertyChanged(sender, e);

			if (e.PropertyName == Layout.IsClippedToBoundsProperty.PropertyName)
				UpdateClipToBounds();
		}

		protected override void UpdateNativeWidget()
		{
			base.UpdateNativeWidget();
			UpdateClipToBounds();
		}

		void UpdateClipToBounds()
		{
			var layout = Element as Layout;
			if (layout != null)
			{
				Clip = null;
				if (layout.IsClippedToBounds)
					Clip = new RectangleGeometry { Rect = new Rect(0, 0, ActualWidth, ActualHeight) };
			}
		}
	}
}