English 中文(简体)
何时用“观点”,LoadData?
原标题:When to Call ViewModel.LoadData?

我有WP7银灯,显示使用Pivot的一组数据。 在首次创建该项目时,视频演播室模板称为Gis Model。 LoadData, p. 1. Loaded:

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    App.ViewModel.LoadData();
}

然而,onMSDN 它说,你应当使用OnNavigated To,而不是第_Loaded页,因为OnNavigated 只有在一页起作用时,才叫到,而“Loaded”页则每当页的视觉树上添加一个物品。 MSDN条款是关于银灯4,而不是用于银灯窗。

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.

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.

是否有任何原因,为什么演练室视像素帕夫模板叫GisModel。 LoadData in page_Loaded?

最佳回答

I think you re confusing LayoutUpdated and Loaded.
Loaded should only get called once each time the page is displayed.

在该网页建成后,将数据与网页具体联系起来是一种简单的处理方式。 我的猜测是,缺省模板使用这一模板,因为它很简单,可以理解和学习。

Update
The article in MSDN that you refer to is for Page.Loaded. WP7 does not use Page instead it uses PhoneApplicationpage.
Having worked with WP7 for over a year and created dozens of apps, I ve never seen the Loaded event called multiple times in a WP7 app.

问题回答

暂无回答




相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签