title: Implement Lazy Loading of Hierarchical StackLayout in Xamarin Forms
body: <p><strong>TL;DR: I want to:</strong></p>
  
  <ol>
  <li>Save some c# object in every StackLayout</li>
  <li>Use information from this object to render another StackLayouts if user wants it.</li>
  </ol>
  
  <p><strong>Details:</strong></p>
  
  <p>I want to display all Html DOM Tree of Objects of some website as a list.</p>
  
  <p>I'm using Html Agility Pack to manage downloaded html. It creates a List of HtmlNode objects that has some HtmlNodes as children, that has some HtmlNodes as children etc. (just like in HTML DOM).</p>
  
  <p>This is what I currently have:</p>
  
  <pre><code>private StackLayout GenerateTreeOfHtmlObjects(HtmlNode htmlNode, int padding)
      {
          StackLayout stackLayout = new StackLayout();
          stackLayout.Orientation = StackOrientation.Vertical;
          foreach (var childNode in htmlNode.ChildNodes)
          {
              if (childNode.Name != "#text")
              {
                  Button showMoreButton = new Button { Text = "&gt;", HorizontalOptions = LayoutOptions.Start, };
  
                  stackLayout.Children.Add(
                      new StackLayout
                      {
                          Children = {
                              showMoreButton,
                              new Label { Text = childNode.Name, FontSize=20 },
                              new Label { Text = new string(childNode.InnerText.Trim().ToCharArray().Take(30).ToArray()), FontSize=15 },
                              new Button { Text = "Zaznacz" },
                              GenerateTreeOfHtmlObjects(childNode, padding+10) //RECURSION, CALL THIS FUNCTION AGAIN AS LONG AS THERE ARE SOME CHILDREN
                          },
  
                          Padding = new Thickness(padding, 0, 0, 10)
                      }
                  );
              }
          }
          return stackLayout;
      }
  </code></pre>
  
  <p>As you see, I'm creating StackLayout for every HtmlNode and add another StackLayouts for their children. It works more or less as I wanted, but the problem is <strong>it takes too much memory and takes very long to load</strong>.</p>
  
  <p>So I want to <strong>load children of some HtmlNode only if user click on their parent</strong>. I will load only those HtmlNodes that are on the top of the tree and successively load their children if they were needed.</p>
  
  <p>To do this, <strong>I need to store somewhere in every StackLayout some information about what to load if user click on it</strong>. Every currently loaded StackLayout has to have HtmlNode class assigned that will allow me to load children of HtmlNode (every HtmlNode has ChildNodes variable and I will take information from there)</p>