我正在尝试使用Windows 8社区预览版在MSVS 11 Beta上使用Metro“Hello World”:
Create Your First Metro Style App using C# or VB
本教程要求您创建一些“模板”页面。例如:
public sealed partial class SplitPage : WindowsBlogReader.Common.LayoutAwarePage
{
...
本教程还要求您覆盖其中一些页面的LoadState()方法:
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// TODO: Assign a bindable group to this.DefaultViewModel["Group"]
// TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"]
FeedData feedData = navigationParameter as FeedData;
if (feedData != null)
{
this.DefaultViewModel["Feed"] = feedData;
this.DefaultViewModel["Items"] = feedData.Items;
}
...
问题是这会导致一个令人讨厌的编译错误:
LoadState(object,System.Collections.Generic.Dictionary<string,object>): no suitable method found to override.
模板的自动生成代码中没有“页面状态管理”区域,也没有默认的“LoadState()”方法(SplitPage.xaml.cs);教程说应该。
问:在较新版本的Metro SDK中,现在是否弃用了LoadState()?
问:我是否需要在.xaml文件中执行“魔术”操作才能使其正常工作?
问:这到底是怎么回事?非常感谢你,如果有人有任何建议的话! 教程还要求您覆盖其中一些页面的LoadState()方法:
答案 0 :(得分:0)
我也遇到了同样的问题,后来我在SplitPage.xaml.cs的方法OnNavigatedTo()中使用了相同的代码,如下所示,它运行正常。
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The
/// Parameter property provides the group to be displayed.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Assign a bindable group to this.DefaultViewModel["Group"]
// TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"]
FeedData feedData = e.Parameter as FeedData;
if (feedData != null)
{
this.DefaultViewModel["Feed"] = feedData;
this.DefaultViewModel["Items"] = feedData.Items;
}
// Select the first item automatically unless logical page navigation is
// being used (see the logical page navigation #region below.)
if (!this.UsingLogicalPageNavigation()) this.itemsViewSource.View.MoveCurrentToFirst();
}
我做的一个小改动是我使用了e.Parameter而不是navigationParameter。
答案 1 :(得分:0)
您是否移植了旧的Metro应用并忘记更新Common文件夹中的LayOutAware页面?