If I'm adding buttons to a StackPanel, when exactly should I run the following code? As it stands just now it's in my OnNavigatedTo function. I'm having to declare that with the "async" property as I've got some code to fetch records from a SQLite DB.
The problem is that when I access this "view record" page, I can see the buttons being drawn one by one (so it takes only a second but there is a definite lag, there's no buttons, then one, then two, then three etc.), the display doesn't appear with the buttons already present, they are added one at a time and it's pretty obvious (this is when using the emulator and an actual device). I wondered if I was just mis-using the OnNavigatedTo event and should be running this code earlier?
I did try doing most of it in the constructor but for some reason I couldn't access the NavgiationContext object (I think that's what it was), for getting the record id from the query string, and I don't think I can declare the constructor with the aysnc property. I think maybe running my code before the initializeComponent() method is called in the constructor could work?
// Add ButtonStackPanel
StackPanel ButtonStackPanel = new StackPanel();
ButtonStackPanel.Name = "ButtonStackPanel";
MainStackPanel.Children.Insert(2, ButtonStackPanel);
// Add Buttons
while (await statement.StepAsync())
{
Button button = new Button();
button.Click += this.disease_Click;
button.Content = Names[statement.GetTextAt(0)];
button.FontSize = 28;
button.Height = 80;
ButtonStackPanel.Children.Add(button);
}
Just looking for some general advice in terms of the order of doing things and if it's alright to have the bulk of my code in the OnNavigatedTo event method.
Thanks