我正在使用 MVVM Light 创建一个 Windows Phone 8 Pivot 应用程序,我想知道如何设计我的 View 模型。应用程序的每个支点(总共 3-4 个)处理不同的数据集合。
我正在考虑的选项是:
你会说哪个选项更好?
最佳答案
只有一个 View 模型,然后为每个 View 模型有单独的集合。有必要的集合项目来绑定(bind)到枢轴项目。
看法
<phone:Pivot x:Name="TutoPivot"
SelectionChanged="PivotSelectionChanged">
<!--Pivot item one-->
<phone:PivotItem Header="{Binding Collection1.Title}">
<!--Double line list with text wrapping-->
<phone:LongListSelector Margin="0,0,-12,0"
SelectionChanged="LongListSelector_SelectionChanged"
LayoutMode="Grid"
GridCellSize="150,150"
ItemsSource="{Binding Collection1.Items}"
ItemTemplate="{StaticResource NewSoundTemplate}"
/>
View 模型:
public class MainModel
{
public ItemViewModel Collection1 { get; set; }
public void LoadData()
{
Collection1=CreateCollection();
制作适当的数据上下文。
教程:Data bound and pivot tutorial
关于c# - 为 Windows Phone 8 枢轴应用程序设计 ViewModel 很热门,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22292670/