The loaded event is not exactly loaded

I feel stupid, but I just can't find the answer to this question. Let's say I want to show a message to users when MainPage loads. The problem is that if I do this at the Loaded event (MessageBox.Show ()), a pop-up window appears immediately before loading my page, which leaves the user with this message and a black background. This is a kind of boring situation. Any ideas that might do the trick. Are there other ways, for example, for a worker background or a NavigationInTransition_EndTransition event, but should there be a more elegant way?

+5
source share
5 answers

You can easily test all standard methods. It took me less time than writing this text to do this.

In the page constructor:

Loaded += new RoutedEventHandler(TestPage_Loaded);
LayoutUpdated += new EventHandler(TestPage_LayoutUpdated);

Relevant methods:

    void TestPage_LayoutUpdated(object sender, EventArgs e)
    {
        Debug.WriteLine("LayoutUpdated");
    }

    void TestPage_Loaded(object sender, RoutedEventArgs e)
    {
        Debug.WriteLine("Loaded");
        Dispatcher.BeginInvoke(() =>
        {
            Debug.WriteLine("Loaded -> BeginInvoke");
        });
    }

Add a debug entry to OnNavigateTo ().

If your page is similar to complex than mine, then you get something like:

  • OnNavigatedTo
  • Layoutupdated
  • Loaded
  • Layoutupdated
  • Uploaded → BeginInvoke
  • many times LayoutUpdated

The last LayoutUpdated will be the best candidate, but how to find it? Therefore, "Loaded → BeginInvoke" seems to be the best option among the trivial ones.

You can also use the Loaded events of individual components on your page. It is also trivially easy. They probably occur between the 4th and 5th steps.

( ), . , , . LayoutUpdated.

+7

Loaded , LayoutUpdated. Loaded. , , , . DeferredLoadContentControl, :

http://www.scottlogic.co.uk/blog/colin/2011/01/windows-phone-7-deferredloadcontentcontrol/

+1

DispatcherTimer LoadedEvent .

+1

Try Page.OnNavigatedTo instead of Loaded.

+1
source

You can also attach it to the Loaded event for one of your controls.

I'm not sure what you want to have in the background (the whole page?), But adding this to which control you want to display might work.

0
source

All Articles