TopContentView by Lelelo1

<PackageReference Include="TopContentView" Version="1.0.2" />

 TopContentView

public class TopContentView : ContentView
using System; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Linq; using System.Reflection; using Xamarin.Forms; namespace Namespace { public class TopContentView { private double width = -1; private double height = -1; public static BindableProperty XProperty = BindableProperty.Create("X", typeof(double), typeof(TopContentView), (object)null, 2, null, new BindingPropertyChangedDelegate((object)<>c.<>9, (IntPtr)(void*)), null, null, null); private double x = -1; public static BindableProperty YProperty = BindableProperty.Create("Y", typeof(double), typeof(TopContentView), (object)null, 2, null, new BindingPropertyChangedDelegate((object)<>c.<>9, (IntPtr)(void*)), null, null, null); private double y = -1; public string Name { get; set; } public double X { get { PropertyInfo property = typeof(VisualElement).GetProperty("X", BindingFlags.Instance | BindingFlags.Public); MethodInfo getMethod = property.GetGetMethod(); return (double)getMethod.Invoke(this, null); } set { x = value; PropertyInfo property = typeof(VisualElement).GetProperty("X", BindingFlags.Instance | BindingFlags.Public); MethodInfo setMethod = property.GetSetMethod(true); setMethod.Invoke(this, new object[1] { value }); } } public double Y { get { PropertyInfo property = typeof(VisualElement).GetProperty("Y", BindingFlags.Instance | BindingFlags.Public); MethodInfo getMethod = property.GetGetMethod(); return (double)getMethod.Invoke(this, null); } set { y = value; PropertyInfo property = typeof(VisualElement).GetProperty("Y", BindingFlags.Instance | BindingFlags.Public); MethodInfo setMethod = property.GetSetMethod(true); setMethod.Invoke(this, new object[1] { value }); } } public unsafe TopContentView() : this() { this.add_PropertyChanged((PropertyChangedEventHandler)delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "X") { double num = -1; if (!object.Equals(x, num)) X = x; double num2 = x; double num3 = X; } else if (e.PropertyName == "Y") { double num4 = -1; if (!object.Equals(y, num4)) Y = y; double num5 = y; double num6 = Y; } if (e.PropertyName == "Parent") { Layout<View> val = this.get_Parent() as Layout<View>; if (val != null) { val.remove_LayoutChanged((EventHandler)TopContentView_LayoutChanged); val.add_LayoutChanged((EventHandler)TopContentView_LayoutChanged); INotifyCollectionChanged notifyCollectionChanged = (INotifyCollectionChanged)val.get_Children(); notifyCollectionChanged.CollectionChanged -= Collection_CollectionChanged; notifyCollectionChanged.CollectionChanged += Collection_CollectionChanged; } } if (e.PropertyName == "Content" && (object)this.get_Content() != null) Listen(this.get_Content()); }); this.add_PropertyChanging(new PropertyChangingEventHandler((object)this, (IntPtr)(void*))); } private unsafe VisualElement Listen(VisualElement visualElement) { visualElement.add_PropertyChanging(new PropertyChangingEventHandler((object)this, (IntPtr)(void*))); Layout<View> val = visualElement as Layout<View>; if (val != null) { foreach (View child in val.get_Children()) { Listen(child); } } else { Layout val2 = visualElement as Layout; if (val2 != null) { PropertyInfo property = ((object)val2).GetType().GetProperty("Content"); MethodInfo getMethod = ((object)val2).GetType().GetProperty("Content").GetGetMethod(); VisualElement visualElement2 = getMethod.Invoke(val2, new object[0]); Listen(visualElement2); } } return visualElement; } private void VisualElement_PropertyChanging(object sender, PropertyChangingEventArgs e) { VisualElement val = sender; if (e.get_PropertyName() == "WidthRequest") this.set_WidthRequest(-1); if (e.get_PropertyName() == "HeightRequest") this.set_HeightRequest(-1); } private void TopContentView_LayoutChanged(object sender, EventArgs e) { Layout<View> val = sender; if (this.get_Width() > 0) width = this.get_Width(); if (this.get_Height() > 0) height = this.get_Height(); double widthRequest = this.get_WidthRequest(); double heightRequest = this.get_HeightRequest(); double num = -1; if (!object.Equals(x, num) && !object.Equals(y, num)) { this.set_WidthRequest(0); this.set_HeightRequest(0); this.Layout(new Rectangle(X, Y, width, height)); } } private void Collection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs eventArgs) { IList<View> list = (IList<View>)sender; IOrderedEnumerable<View> second = from element in list orderby element is TopContentView select element; if (!list.SequenceEqual(second)) Device.BeginInvokeOnMainThread((Action)delegate { (this.get_Parent() as Layout<View>).RaiseChild(this); }); } } }