Forum Xamarin.Android

Can't add children to stacklayout programmatically.

MalfunctionMalfunction Member ✭✭
edited January 2018 in Xamarin.Android

Hi! i don't seem to be able to add children to the stacklayout unless i do it through a gesture event like the one below. If i move the contents of OnButtonTapped() into LoadList() and call LoadList() from another class it will go through the method but the child never gets added. No crash or errors. Help?

`private void OnButtonTapped(object sender, EventArgs e)
    {
        Label label = new Label();

        label.Text = "item 2";

        Stacklist.Children.Add(label);
    }

    public void LoadList()
    {


    }`

Answers

  • EricSchmeckEricSchmeck DEMember ✭✭

    Hi, try using RunOnUiThread, like this:
    RunOnUiThread(()=>
    {
    //Your code
    });

  • MalfunctionMalfunction Member ✭✭

    @EricSchmeck said:
    Hi, try using RunOnUiThread, like this:
    RunOnUiThread(()=>
    {
    //Your code
    });

    That doesnt seem to exist in Xamarin.Forms. Seems that i posted this in the wrong forum aswell as i just now realise im in Xamarin.android.

Sign In or Register to comment.