Hallo.
I have 2 BoxViews, where i want the first box, to be like a showdow for the second box.
I used a AbsoluteLayout layout to accomplish this.
AbsoluteLayout layout = new AbsoluteLayout();
{ };
AbsoluteLayout.SetLayoutFlags(boxOne, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(boxOne, new Rectangle(0, 1, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
AbsoluteLayout.SetLayoutFlags(boxTwo, AbsoluteLayoutFlags.XProportional);
AbsoluteLayout.SetLayoutBounds(boxTwo, new Rectangle(0.5, 1, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
This works great, no probelms at all.
Then i wanted to put a GradientLayer a a background Color, on each box. The first box i position fine, but the next box, is not placed in the middel anymore, it seems like, the customrender i use, take the new Rectangle(0.5,
x postition, and translate into pixel, how do i avoid this, so i can keep the absoluteLayout position.
CustomRender
[assembly: ExportRenderer(typeof(GradientBoxView), typeof(GradientBoxviewRender))]
namespace ChartClients.iOS
{
public class GradientBoxviewRender : BoxRenderer
{
public CAGradientLayer gradientLayer;
protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
{
base.OnElementChanged(e);
if (Element != null)
{
var gradientBoxView = e.NewElement as GradientBoxView;
gradientLayer = new CAGradientLayer();
if (gradientBoxView != null)
{
gradientLayer.Frame = gradientBoxView.Bounds.ToRectangleF();
gradientLayer.Colors = new[] { gradientBoxView.EndColor.ToCGColor(), gradientBoxView.StartColor.ToCGColor() };
}
Layer.MasksToBounds = true;
Layer.InsertSublayer(gradientLayer, 0);
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
var boxView = sender as GradientBoxView;
if (e.PropertyName == VisualElement.HeightProperty.PropertyName)
{
gradientLayer.Frame = boxView.Bounds.ToRectangleF();
UpdateCornerRadius(Element as GradientBoxView);
}
Thanks