locked
How to detect when app is completely loaded.

    Question

  • How can I detect when a xaml is completely finished loading? I know each component has a 'loaded' event but that doesn't help me unless I know the final component that loads.  On other platforms there are events that fire when loading is complete is this not the case on Windows?

    The situation is that I load a pile of settings and place them into the ui.  Then those values are used to do a pile of calculations and the results are placed into more ui components.  I could load each setting separate as each individual component loads but the calculated values can't do this. 

    Any help would be great.

    Sunday, June 08, 2014 4:48 PM

All replies

  • Only you, the developer, decides which one is the final component that loads. For example if you have a twitter client showing its homepage that dynamically add components in real time, there may never be a final component as the client will probably always be in the loading status. Loading sequence is your application's business logic, not something the OS gets involved with.


    Visual C++ MVP


    Sunday, June 08, 2014 6:29 PM
  • Well that sounds like a buncha hippy, dippy, bologna.  I have worked with Xcode, Qt, Eclipse, Blackberry, and they all fire an event when the page, window, whatever is completed loading the ui components.  I don't see how I the omnipotent developer has any say over when the components are completed loading.

    The best I can see is the onNavigated event but if I try to programmatically set the selected index of a combobox I get an error because the combobox isn't finished loading.  In xcode (or any other development environment for that matter) I simply set the selected index within the main page's onLoaded event.  Once that onLoaded event is fired I know everything else is initialized already (of course).

    Sunday, June 08, 2014 7:08 PM
  • The OnNavigatedTo virtual method is invoked before the template is loaded, thus elements from templates aren't available yet. The Window.Loaded event is for the initial layout of a window, but since you specifically reject it, it sounds like you are changing the child control layouts AFTER the loaded event. 

    Your XCode Page.onLoaded example would not work with a twitter client example either. It's role is the same as Window.Loaded. It just tell you the initial layout is done and does not notify you of layout changes made aferwards.



    Visual C++ MVP


    Sunday, June 08, 2014 7:34 PM
  • Every FrameworkElement has a Loaded event.

    If you want to set the selected index of a combo box when it is loaded add an event handler to your combobox.

    <ComboBox Loaded="YourEventhandler" />

    public void YourEventHandler(object sender, RoutedEventArgs args){
        ComboBox comboBox = sender as ComboBox;
        comboBox.SelectedIndex = 1;
    }


    Sunday, June 08, 2014 8:25 PM
  • Yes I realize each component has an onLoaded event.  That doesn't help.  I need to know when all components are done loading not just an individual one.  Again I reference Xcode (but I have also seen similar pretty much across the board) when viewDidLoad() fires you can safely work with your ui knowing that all ui components have been loaded and initialized.  I am looking for a similar event on Windows.  Does anyone know if there is one or isn't one?  Or does anyone know what the logic is to the order of loading?  I assume the parent objects are loaded and than down the tree to the child objects but that doesn't help either since most of my components are same level child objects.
    Sunday, June 08, 2014 9:30 PM
  • First runs the this.InitializeComponent() in the Page Constractor and last the OnNavigatedTo(thats what I know maybe Im wrong).

    When I want to load values into the UI I usually create an async Task and call it in OnNavigatedTo.

    A solution is to do calculations programmatically and bind the values with INotifyPropertyChanged.

    Sunday, June 08, 2014 10:52 PM
  • You'd be better off to look at the concept of DataBinding - it's a more efficient way of doing things. 

    Basically, you just need to worry about loading your data into a class/collection - because all your controls would be bound to that data.

    As the data changes, so does the UI (without any code-behind required) and even optionally the reverse - when the UI changes, so does the data.  You'd then wire in the events in your data to do complex things, or page navs.

    You don't have to worry about when a control *is*, you just have to worry about the data fed to the control - and the control does the rest.   There are other benefits too - being able to see your UI at dev time in the editor instead of having to always do the compile/debug/edit loop.


    Darin R.

    • Proposed as answer by St4mos Wednesday, June 18, 2014 11:48 AM
    Monday, June 09, 2014 9:03 PM