简体   繁体   English

Windows Phone 8:如何使用MVVM加载每个数据透视表项的内容?

[英]Windows Phone 8 : How to load content for each pivot item using MVVM?

I am using Pivot Control in my app. 我在我的应用程序中使用数据透视控件。 I want to load content of each pivot item through remote url (ie using Web services). 我想通过远程URL(即使用Web服务)加载每个数据透视项目的内容。

For Example - I have a detailed Pivot Page of a recipe. 例如-我有一个食谱的详细数据透视页面。 It has 3 pivot items - info, reviews, gallery.And it has Progress indicator on system tray. 它具有3个关键项-信息,评论,图库,并且在系统托盘上具有进度指示器。

I want to load data of each pivot item once ie if user swipes back to the previously loaded pivot item, then it should not make web request again for that pivot item and Progress Indicator should be invisible in that case. 我想一次加载每个枢纽项目的数据,即,如果用户滑动回到先前加载的枢纽项目,则它不应再次对该枢纽项目进行Web请求,并且在这种情况下进度指示器不可见。

Should I use different ViewModel for each pivot item or single MainViewModel for all? 我应该为每个枢轴项目使用不同的ViewModel还是为所有数据透视表使用单个MainViewModel?

How to manage the visibility of Progress indicator in Pivot page? 如何在“数据透视”页面中管理进度指示器的可见性?

Should I create UserControl for each Pivot item? 我应该为每个数据透视表项创建UserControl吗?

The pages role is to show data for one "entity", the recipe. 页面的作用是显示一个“实体”(配方)的数据。 Because of this, I would use just one RecipeViewModel and also would not bother creating UserControls for the Pivot items. 因此,我将只使用一个RecipeViewModel,也不会为Pivot项创建UserControls。

You can use binding for managing the ProgressIndicator. 您可以使用绑定来管理ProgressIndicator。 I personally use a BasePage inherited from PhoneApplicationPage where I create the binding in code behind, eg: 我个人使用从PhoneApplicationPage继承的BasePage,在其中我在后面的代码中创建绑定,例如:

if (SystemTray.ProgressIndicator == null)
{
    var indicator = new ProgressIndicator { IsIndeterminate = true };
    var visibilityBinding = new Binding("ProgressBarIsActive");
    BindingOperations.SetBinding(indicator, ProgressIndicator.IsVisibleProperty, visibilityBinding);        
    SystemTray.SetProgressIndicator(this, indicator);

} }

With this, you just need to toggle the ProgressBarIsActive property on your ViewModel. 这样,您只需要在ViewModel上切换ProgressBarIsActive属性即可。

I would use different ViewModels for pivot items only when the pivot items are indetendent (eg: list of recipes, contact info, about in one Pivot). 仅当枢轴项目独立时,我才会对枢轴项目使用不同的ViewModels(例如:配方列表,联系信息,关于一个Pivot)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM