Nitish Bangad
Nitish Bangad

Reputation: 151

which method is first called when a xaml page is loaded in windows phone by default?

I want to know which method is first called by default when a xaml page is loaded in windows phone app and how can I change the method which has to be called first on load?

Upvotes: 6

Views: 9882

Answers (3)

Felix
Felix

Reputation: 4081

You can also set the Loaded handler via xaml:

.xaml:

<Page
    ...
    Loaded="OnPageLoaded">

.xaml.cs:

private void OnPageLoaded(object sender, RoutedEventArgs e)
{
    ...
}

Upvotes: 3

Rajeev Bhatia
Rajeev Bhatia

Reputation: 2994

To automatically perform an action on page load, use this in your page constructor:-

public MainPage()
{
    InitializeComponent();

    Loaded += (s, e) =>
    {
        //write logic here
    }
}

Upvotes: 12

Joe Brunscheon
Joe Brunscheon

Reputation: 1999

To directly answer your question: Initialize is the event you are looking for.

For more detailed information, Google is your friend:

Application lifecycle - http://msdn.microsoft.com/en-us/windowsphonetrainingcourse_applicationlifetimewp7lab_topic2.aspx

Controls and other objects should follow the standard event lifecycle:

http://msdn.microsoft.com/en-us/library/ms754221.aspx

Upvotes: -2

Related Questions