【问题标题】:Metro/Windows8 compile error: LoadState() => no suitable method found to overrideMetro/Windows8 编译错误:LoadState() => 找不到合适的方法来覆盖
【发布时间】:2012-06-02 05:20:04
【问题描述】:

我正在尝试使用 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.

模板(SplitPage.xaml.cs)的自动生成代码中没有“页面状态管理”区域,也没有默认的“LoadState()”方法;教程说应该有。

问:LoadState() 现在在 Metro SDK 的新版本中被弃用了吗?

问:我需要在 .xaml 文件中做一些“魔术”来完成这项工作吗?

问:这到底是怎么回事?

非常感谢您,如果有人有任何建议! 教程还要求您覆盖其中一些页面的 LoadState() 方法:

【问题讨论】:

  • 你的基类LayoutAwarePage 包含LoadState,所以protected override void LoadState(Object navigationParameter, Dictionary&lt;String, Object&gt; pageState) 可以工作。然而,我在这里偶然发现,因为我的 LoadState(...) 没有执行。 ://

标签: c# microsoft-metro winrt-xaml


【解决方案1】:

我也遇到了同样的问题,后来我在 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 。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2020-07-01
      • 2022-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-05
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      相关资源
      最近更新 更多