In Silverlight, what's the difference between UserControl_Loaded and Page_Loaded?

I'm trying to write a silverlight app that takes InitParams and then uses those InitParams to make changes to the Source

pages MediaElement

on the page. I am trying to find a suitable place to put my code.

I watched Tim Heuer's excellent video on InitParams, but in the video (which was for Silverlight 2) it shows the following on Page.xaml.cs:

void Page_Loaded(object sender, RoutedEventArgs e)
    {

    }

      

I don't see Page_Loaded when I open MainPage.xaml.cs and I'm wondering if this was auto-generated in the Silverlight 2 SDK and left outside of the Silverlight 3 SDK. Or perhaps Tim added this manually to his video.

I found that I can go into the opening UserControl MainPage.xaml tag and add Loaded="<New_Event_Handler>"

that creates the following in MainPage.xaml.cs:

private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {

    }

      

By default, MainPage.xaml.cs also does the following: during the Application_Startup event in App.xaml.cs:

public MainPage()
    {            
        InitializeComponent();
    }

      

I need to figure out where is the best place to insert my code to change Source

on mine MediaElement

in my xaml. Should I put it in MainPage

? Should I add an event handler Loaded

and place it in UserControl_Loaded

? If it should be Page_Loaded

, where can I find that in Silverlight 3?

Any help would be much appreciated.

+2


source to share


1 answer


"UserControl_Loaded" and "Page_Loaded" are just method names, and the names don't matter (you could call the method "Foo" if you like). What makes these methods something is that they are attached to the Loaded event on the UserControl (which is what you did when you edited the MainPage.xaml file).



+2


source







All Articles