Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

When does OnAppearing Fires on different Platforms?

$
0
0

Hey Guys,
I ran into a Problem concerning the OnAppearing event on iOS and WP.
My Page got the following structure:
Picker1 -> Picker2 (based on the entry in Picker1) -> Multiple Label – Switch Elements based on the entry in Picker2.
So I want my application to start with informations loaded. When I define selectedIndex=0 to Picker1 in the constructor, the selectedIndex Event fires but on IOS the Switch controls doesn’t load. On WP this solution worked perfectly.

` if (Customer_picker.SelectedIndex == -1)
Customer();

        OrderLabel = new Label[customer[Customer_picker.SelectedIndex].Projects[Projects_picker.SelectedIndex].Orders.Count];
        Orderswitch = new Switch[customer[Customer_picker.SelectedIndex].Projects[Projects_picker.SelectedIndex].Orders.Count];


        int i = 0;
        Grid g = new Grid()
        {
            ColumnDefinitions = 
            {
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
                new ColumnDefinition { Width = GridLength.Auto },
            }
        };
        g.Children.Clear();

        foreach (ApiOrder o in customer[Customer_picker.SelectedIndex].Projects[Projects_picker.SelectedIndex].Orders)
        {

            OrderLabel[i] = new Label();

            OrderLabel[i].Text = o.Name;
            OrderLabel[i].VerticalOptions = LayoutOptions.Center;
            OrderLabel[i].TextColor = Color.FromHex("#FF4D82B8");

            Orderswitch[i] = new Switch();

            Orderswitch[i].VerticalOptions = LayoutOptions.Center;
            Orderswitch[i].HorizontalOptions = LayoutOptions.EndAndExpand;
            Orderswitch[i].HeightRequest = 65.0;

            Orderswitch[i].Toggled += switcher_Toggled;

            g.Children.Add(OrderLabel[i], 0, i);
            g.Children.Add(Orderswitch[i], 1, i);

            ++i;
        }

        OrderList.Children.Clear();
        OrderList.Children.Add(g);`

My next Idea was to solve this Problem by moving the selectedIndex =0 Event to the OnAppearing Event. But this makes my iOS App crash because I think the OnAppearing Event fires before the Picker is available. When I debug this construct on WP I can see, that the Page gets opened AFTER the constructor finished. On iOS it seems like the event fires to early.
My code is getting really messy and my current solution is to “re-call” the method in case of an exception.

I got three questions now.
1: Why isn't my first solution not working on iOS.
2: When does the onAppearing Event fires. Isn't it supposed to fire after the constructor is done on every device?
3: Is there a better solution to check if Controls are loaded then catching the exception and recall the method?

Greetings
Julian.


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>