1

I have created a custom control which is extended from ContentView in Xamarin.Forms. I have layout the Content for some scenario using LayoutChildren override method in Forms. This is working fine up to XF version 4.8. After upgrade to Xamarin.Forms 5.0, this LayouChildren override method is not called and Content also not displayed in UWP. I suspect that, in Xamarin.Forms 5.0 layout/arrange operation is not performed for Content.

Note: If i add the same custom control within Grid, custom control's Content is displayed.

  1. I simply created a small custom control to reproduce my issue. Created custom control in Xamarin.Forms

    public class CustomContentView: ContentView
     {
         public CustomContentView()
         {
         }
    
         protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
         {
             return base.OnMeasure(widthConstraint, heightConstraint);
         }
         protected override void LayoutChildren(double x, double y, double width, double height)
         {
             base.LayoutChildren(x, y, width, height);
         }
     }
    
  2. Created custom renderer for this Forms control in UWP renderer project. Native UWP control is extended from ContentPresenter. I have converted Forms content to native and set to content control's content. Then assigned content control to Native control.

Native control in UWP

public class CustomView : ContentPresenter
    {
        public CustomView()
        {
        }
    }

Renderer class

public class CustomRenderer : VisualElementRenderer<CustomControl.CustomContentView, CustomView>
    {
        private CustomView customView;
        public CustomRenderer()
        {
            this.AutoPackage = false;
        }
        protected override void OnElementChanged(ElementChangedEventArgs<CustomContentView> e)
        {
            if (e.NewElement == null)
            {
                return;
            }

            this.customView = new CustomView();
            this.customView.DataContext = this.Element.BindingContext;
            this.SetNativeControl(this.customView);

            if (Element.Content != null)
            {
                var renderer = Element.Content.GetOrCreateRenderer();
                var contentControl = new ContentControl();

                contentControl.Content = renderer.ContainerElement;
                this.customView.Content = contentControl;
            }
            base.OnElementChanged(e);
        }
    }

Steps to Reproduce

  1. Run the attached sample (Sample link given in Reproduction Link)
  2. Added Button control as content in my custom control. But it is not displayed.

Expected Behavior

Content (Button) should be displayed

Sample link with custom control:

Anyone please confirm whether this is custom control(XF5.0) or framework side issue?

Cfun
  • 8,442
  • 4
  • 30
  • 62
Bharathi
  • 1,288
  • 2
  • 14
  • 40
  • I test the sample and get same result as you. I find you already opened an [issue](https://github.com/xamarin/Xamarin.Forms/issues/13492) and follow the response there. – nevermore Jan 22 '21 at 06:24
  • Yes. Already opened issue in github. Meanwhile, trying to get solution from other forum (stack overflow) too. Thanks – Bharathi Jan 22 '21 at 06:35
  • OK, good luck. I think the problem is probably caused by what PureWeen said in that thread. – nevermore Jan 22 '21 at 07:46

0 Answers0