Bug 34206 - Can't dinamically Add layouts to content of a scrollView
Summary: Can't dinamically Add layouts to content of a scrollView
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-09-23 10:23 UTC by Estef
Modified: 2016-01-20 13:57 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Estef 2015-09-23 10:23:06 UTC
When trying to dinamically add layouts to the content of a scrollView, it doesn't render until the second layout added.
For example: This code add a layout each time the user click the button, for some reason it doesn't render the first layout added.

public class PageExperiment
{
    ScrollView _page;

    public PageExperiment()
    {
        _page = new ScrollView { Orientation = ScrollOrientation.Vertical,
                                 Content = new RelativeLayout { BackgroundColor = Color.White} };

        var button = new Button { Text="Add Button"};
        button.Clicked += OnButtonClicked;
        ((RelativeLayout)_page.Content).Children.Add(button,xConstraint:null);
    }

    public ScrollView getPage()
    {
        return _page;
    } 
    void OnButtonClicked(object sender, EventArgs e)
    {
        var relative = AddLayout();
        var content = (RelativeLayout)_page.Content;
        var v = content.Children[content.Children.Count - 1];
        Constraint xConstraint = Constraint.Constant(0);
        Constraint yConstraint = Constraint.RelativeToView(v, (parent, sibling) => {
            return sibling.Y + sibling.Height;
        });            

        ((RelativeLayout)_page.Content).Children.Add((View)relative, xConstraint, yConstraint);        

    }

    public VisualElement AddLayout()
    {
        var root = new RelativeLayout();

        root.BackgroundColor = Color.Red;
        var a = new Label { Text = "Button Added!!!!", BackgroundColor = Color.Purple};
        a.FontSize = 30;
        root.Children.Add(a, xConstraint:null);

        return root;
    }
}

Here is the main:

public class App : Application
{
    public App()
    {
        var root = new PageExperiment();
        MainPage = new ContentPage
        {
            Content = root.getPage()
        };

    }
}
Comment 1 David Strickland 2015-09-26 11:59:03 UTC
Chased this for a bit today. It does appear to be occurring for me as well.

I did simplify the code above a bit. From what I can tell It's not just layouts, it appears that no visual elements will add on the first trip through the event handler.

using System;
using Xamarin.Forms; 
namespace ScrollViewPageExperiment
{
 public class PageExperiment
 {
  ContentView view;
  public ContentView getPage()
  {
   return view;
  } 

  public PageExperiment()
  {
   view = new ContentView {Content = new RelativeLayout()};
   var button = new Button { Text="Add"};
   button.Clicked += OnButtonClicked;
   ((RelativeLayout)view.Content).Children.Add(button,Constraint.Constant(0),Constraint.Constant(0));
  }
  void OnButtonClicked(object sender, EventArgs e)
  {
   var testLabel = new Label { Text="test"};
   int controlCount = ((RelativeLayout)view.Content).Children.Count;
   ((RelativeLayout)view.Content).Children.Add(testLabel,
      ()=>0,)=>controlCount*10+30);
  }
 }
}
Comment 2 Stephane Delcroix 2016-01-20 13:57:57 UTC
Using the code from comment #2, I was unable to reproduce the reported behavior on either iOS or Android.

If you still can trigger it using latest Xamarin.Forms release, please reopen this issue, with some extra information about the platform (type, version, device) you use for producing this failure.

Warm regards,

the xf team