I don't get how this content is being displayed

Hey guys so basically I don't get how this content is displayed it doesn't make sense to me. So basically it makes 10 buttons 0-9 and that's fine it gets stored in a stacklayout called "rowStack" and there is another stacklayout called "mainStack" What doesn't make sense to me is how the buttons are actually on the screen? Because we set "this.content = mainStack" so the content we display is mainstack not rowStack, mainstack does not contain any buttons so how is it that this line "this.content = mainStack" actually displays the buttons?

`
StackLayout rowStack = null;
//loop through 10 times
for (int num = 1; num <= 4; num++)
{
//check if index currently at is 0-3-6-9
if ((num - 1) % 3 == 0)
{

                //create a new stacklayout
                rowStack = new StackLayout
                {
                    //set orientation to horizontal
                  //  Orientation = StackOrientation.Horizontal
                };  



                //add to the mainstack whatever is in rowstack 
                mainStack.Children.Add(rowStack);

            }

            //create new button
            Button digitButton = new Button
            {
                Text = (num % 10).ToString(),
                FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
                StyleId = (num % 10).ToString()

            };
     //       digitButton.Clicked += OnDigitButtonClicked;

            //if (num == 10)
            //{
            //    digitButton.HorizontalOptions = LayoutOptions.FillAndExpand;
            //}

            //add to the rowstack button
         //   rowStack.Children.Add(digitButton);
            rowStack.Children.Add(digitButton);
            //set content of page to content inside mainstack
            this.Content = mainStack;
        }`

Best Answers

Answers

  • Thanks guys.

Sign In or Register to comment.