How to access control on current TabbedPage?

JamieConroy.0603JamieConroy.0603 USMember
edited November 2016 in Cross Platform with Xamarin

I have a tabbed page with a stacklayout that I populate with some child controls. The page originally had no navigation but now I've added the tabbed page (created programmatically in the app.cs) it means that the method below is unable to populate the selected tabbed page's stacklayout.

I need to know how to access the current tabbed page and then add the items to the stacklayout.

public static void addToReadout(string name, string time, string inout)
{
    try
    {
        Label label1 = new Label { Text = name + " Successfully clocked " + inout + " @ " + time, TextColor = Color.Black };
        StackLayout sl = new StackLayout();


        var mp = (MainPage)App.Current.MainPage;


        if (mp.readOut.Children.Count() < 7)
        {

            mp.readOut.Children.Add(label1);
            mp.readOut.Children.Count();
        }
        else
        {
            mp.readOut.Children.RemoveAt(0);
            mp.readOut.Children.Add(label1);
            mp.readOut.Children.Count();
        }

    }
    catch (Exception ex)
    {

        ErrorRepository.InsertError(ex.ToString());
    }
}

This issue is with this row since changing to a tabbed page setup:

var mp = (MainPage)App.Current.MainPage;
Sign In or Register to comment.