Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] [UWP] LayoutChildren method is not called in custom control after upgrade Xamarin.Forms 5.0 #13492

Closed
bharathirajauk opened this issue Jan 21, 2021 · 1 comment · Fixed by #13640
Assignees
Labels
5.0.0 Regression on 5.0.0 i/regression in-progress This issue has an associated pull request that may resolve it! t/bug 🐛
Milestone

Comments

@bharathirajauk
Copy link

bharathirajauk commented Jan 21, 2021

Description

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. I suspect that in Xamarin.Forms 5.0, layout process 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);
        }
    }
  1. 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

  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

Actual Behavior

Display with blank page.

Basic Information

  • UWP: All SDK version
  • NuGet Packages: Xamarin.Forms: 5.0.0.1905

Reproduction Link

Sample link with custom control: https://github.com/bharathirajauk/MySamples/blob/master/CustomControl_XF5.0.zip?raw=true

@bharathirajauk bharathirajauk added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 21, 2021
@PureWeen
Copy link
Contributor

@hartez it looks like this is a regression from

#12017

It looks like because the Layout is no longer marshaled to the UI Thread the layout code never gets beyond this point

I'm guessing before when it was all being executed from Device.BeginInvoke that the renderers were getting attached before the layout code processed

@PureWeen PureWeen added 4.8.0 regression on 4.8.0 i/regression labels Jan 21, 2021
@PureWeen PureWeen added this to the 5.0.0 milestone Jan 21, 2021
@hartez hartez removed the s/unverified New report that has yet to be verified label Feb 2, 2021
hartez added a commit that referenced this issue Feb 3, 2021
hartez added a commit that referenced this issue Feb 3, 2021
@hartez hartez added in-progress This issue has an associated pull request that may resolve it! 5.0.0 Regression on 5.0.0 and removed 4.8.0 regression on 4.8.0 labels Feb 3, 2021
PureWeen pushed a commit that referenced this issue Feb 5, 2021
* Move layout change resolution call up to VisualElement
Fixes #13418
Fixes #13492

* Signal layout request when CollectionView is in a layout
Fixes #13551

* Fix layout error loop from test 12714

* Fix autolayout issues when CollectionView size is less than span;

* Provide measurement for default text cells (no ItemTemplate);

* Cleanup
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
5.0.0 Regression on 5.0.0 i/regression in-progress This issue has an associated pull request that may resolve it! t/bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants