我开始学习Windows 8商店应用。
我还记得之前在Silverlight和WPF编程中,人们采用MVVM模式,现在我不确定是否应该使用之前所学的内容。
我添加了GalaSoft.MvvmLight参考,并创建了一个ViewModel并根据以下建议将其添加到我的xaml中:
DataContext="{Binding Source={StaticResource Locator}, Path=Welcome}"
看起来微软在LayoutAwarePage中包含了某种ModelView实现:
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// TODO: Assign a bindable collection of items to this.DefaultViewModel["Items"]
// DefaultViewModel["WelcomeTiles"] = WelcomeTiles;
}
如果设置了以下数据上下文,则可以访问。
<DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" />
现在我不确定是否应该像我记得的那样使用MVVMLight来创建ModelViews,还是将数据添加到DefaultViewModel的code-behind文件中。
大家对这两种方式有什么经验吗? 我刚刚开始,我的下一个目标是为GridView中点击项目时添加处理程序-哪种方法可以让我轻松完成?