title: Is there any way that I can speed up the adding of new elements to a page when using the C# back end?
body: <p>I have code that works but I notice it's rather slow to create the page elements. </p>
  
  <p>Here's what I have so far. Note that I'm not adding everything at once as I found that when I did the page creation was even slower.</p>
  
  <pre><code>    public void CreateSwitchSection(bool? selected)
      {
          Application.Current.Resources.TryGetValue("FrameBorder", out object frameBorder);
          var st = new StackLayout { Orientation = StackOrientation.Vertical, Spacing = 0 };
          st.Children.Add(AddSwitchRows(selected, App.cardSetWithWordCount.Take(20)));
          st.Children.Add(AddSwitchRows(selected, App.cardSetWithWordCount.Skip(20).Take(20)));
          st.Children.Add(AddSwitchRows(selected, App.cardSetWithWordCount.Skip(40).Take(20)));
          st.Children.Add(AddSwitchRows(selected, App.cardSetWithWordCount.Skip(60).Take(20)));
          st.Children.Add(AddSwitchRows(selected, App.cardSetWithWordCount.Skip(80).Take(20)));
          var fr = new Frame { Style = (Style)frameBorder };
          var fs = new FrameStack { };
          var ht = new HeaderTemplate()
          {
              Text = "CHOOSE CARD SETS FOR THE DECK"
          };
          fs.Children.Add(ht);
          fs.Children.Add(st);
          fs.Children.Add(new LineTemplate());
          fr.Content = fs;
          details.Children.Clear();
          details.Children.Add(fr);
      }
  
      private StackLayout AddSwitchRows(bool? selected, IEnumerable&lt;CardSetWithWordCount&gt; data)
      {
          var stack = new StackLayout
          {
              Orientation = StackOrientation.Vertical,
              Spacing = 0
          };
  
          foreach (var x in data)
          {
              var cell = new BadgeGridTemplate
              {
                  BindingContext = x,
                  Text = x.Name,
                  State = selected == true ? "E" : "D",
                  Message = x.TotalWordCount.ToString(),
                  TapCommand = (Command)vm.SelectCardSetCmd,
                  RowId = x.Id,
                  Separator = true
              };
              stack.Children.Add(cell);
          }
          return stack;
      }
  </code></pre>
  
  <p>For reference here is the BadgeGridTemplate I coded:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;t:BaseGridTemplate xmlns="http://xamarin.com/schemas/2014/forms" 
                      xmlns:t="clr-namespace:Japanese.Templates" 
                      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                      xmlns:local="clr-namespace:Japanese;assembly=Japanese" 
                      xmlns:b="clr-namespace:Behaviors;assembly=Behaviors" 
                      xmlns:converters="clr-namespace:Japanese.Converters;assembly=Japanese" 
                      x:Class="Japanese.Templates.BadgeGridTemplate" 
                      x:Name="this" 
                      HeightRequest="{DynamicResource GridHeight}" Margin="0"
      Orientation="Vertical" Spacing="0"&gt;
      &lt;BoxView HeightRequest="1" HorizontalOptions="FillAndExpand" IsVisible="{Binding Separator, Source={x:Reference this}}" BackgroundColor="{DynamicResource LineColor}" Margin="0" /&gt;
      &lt;Grid Padding="20,0" VerticalOptions="CenterAndExpand"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition /&gt;
              &lt;ColumnDefinition Width="Auto" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Label Grid.Column="0" Text="{Binding Text,  Source={x:Reference this}}" TextColor="{DynamicResource LabelColor}" Style="{StaticResource LabelText}" VerticalTextAlignment="Center" WidthRequest="30" /&gt;
          &lt;t:Button Grid.Column="1" Meta="GsT" RowId="{Binding RowId, Source={x:Reference this}}" State="{Binding State, Source={x:Reference this}}" TapCommand="{Binding TapCommand, Source={x:Reference this}}" Text="{Binding Message, Source={x:Reference this}}" Theme="{Binding Theme}" WidthRequest="30" /&gt;
      &lt;/Grid&gt;
  &lt;/t:BaseGridTemplate&gt;
  </code></pre>