Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen to Call ViewModel.LoadData?
    primarykey
    data
    text
    <p>I have a WP7 Silverlight app that displays a bunch of data using Pivot. When first creating the project, the Visual Studio template calls ViewModel.LoadData in Page_Loaded:</p> <pre><code>private void MainPage_Loaded(object sender, RoutedEventArgs e) { App.ViewModel.LoadData(); } </code></pre> <p>However <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.page.onnavigatedto%28VS.95%29.aspx" rel="nofollow">on MSDN</a> it says you should use OnNavigatedTo instead of Page_Loaded, because OnNavigatedTo is called only once when a page becomes active, while Page_Loaded is called everytime an item is added to the page's visual tree. The MSDN article is for Silverlight 4 instead of for Silverlight Windows Phone though.</p> <blockquote> <p>You override the OnNavigatedTo method to examine the navigation request and prepare the page for display. For example, you can load the requested data and enable or disable visual elements. </p> <p>Typically, you use the OnNavigatedTo method instead of creating an event handler for the Loaded event. The OnNavigatedTo method is preferable because it is only called once for each time the page becomes active. The Silverlight framework raises the Loaded event each time the element is added to the visual tree, which potentially can happen more than once when activating a page. The OnNavigatedTo method is called for each request, even when the page is retrieved from the cache. You should include in this method code that must be executed for each request rather than placing that code in the Page constructor.</p> </blockquote> <p>Is there any reason why the Visual Studio Pivot template calls ViewModel.LoadData in Page_Loaded?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload