0

I'm trying to work through this Metro "Hello World" on MSVS 11 Beta, with the Windows 8 Community Preview:

Create Your First Metro Style App using C# or VB

The tutorial asks you to create some "template" pages. For example:

public sealed partial class SplitPage : WindowsBlogReader.Common.LayoutAwarePage
{
   ...

The tutorial also asks you to override the LoadState() method for some of these pages:

    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;
        }
        ...

The problem is that this dies with a nasty compile error:

LoadState(object,System.Collections.Generic.Dictionary<string,object>): no suitable method found to override.

There is no "Page state management" region and no default "LoadState()" method in the auto-generated code for the template (SplitPage.xaml.cs); the tutorial says there should be.

Q: Is LoadState() now deprecated in newer versions of the Metro SDK?

Q: Do I need to do something "magic" in a .xaml file to make this work?

Q: What the heck is going on here?

Thank you very much in advance, if anybody has any suggestions! tutorial also asks you to override the LoadState() method for some of these pages:

4

2 回答 2

0

您是否移植了旧的 Metro 应用程序并忘记更新 Common 文件夹中的 LayOutAware 页面?

于 2012-07-03T18:23:02.360 回答
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 。

于 2012-06-07T16:51:15.123 回答