Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LoadState和navigationHelper\u LoadState之间的差异_C#_Windows Store Apps_Winrt Xaml - Fatal编程技术网

C# LoadState和navigationHelper\u LoadState之间的差异

C# LoadState和navigationHelper\u LoadState之间的差异,c#,windows-store-apps,winrt-xaml,C#,Windows Store Apps,Winrt Xaml,我是windows应用商店应用程序开发新手。目前,我正在研究使用c#在XAML之间传递和接收参数 有人能用一些例子解释一下LoadState()和navigationHelper\u LoadState()之间的区别吗?我应该选择哪个接收参数?网上有很多例子。你最好先看看这些,然后再回来问更具体的问题 因此,NavigationHelper.LoadState需要两件事: on导航到当此页面即将显示在框架中时调用 NavigationMode.New导航是指向页面的新实例(不是向前或向后) 说:

我是windows应用商店应用程序开发新手。目前,我正在研究使用c#在XAML之间传递和接收参数


有人能用一些例子解释一下
LoadState()
navigationHelper\u LoadState()
之间的区别吗?我应该选择哪个接收参数?

网上有很多例子。你最好先看看这些,然后再回来问更具体的问题


因此,NavigationHelper.LoadState需要两件事:

  • on导航到
    当此页面即将显示在框架中时调用
  • NavigationMode.New
    导航是指向页面的新实例(不是向前或向后)
  • 说:

    除了提供前面描述的实现之外,还需要从每个页面上实现的OnNavigatedTo()和OnNavigatedFrom()事件处理程序调用NavigationHelper。发生这些事件时,NavigationHelper调用LoadState()和SaveState()的特定于页面的实现。您可以在每个页面上自定义这些功能的实现。它们应该分别代替OnNavigatedTo()和OnNavigatedFrom()

    原始代码是:

    public void OnNavigatedTo(NavigationEventArgs e)
    {
        var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
        this._pageKey = "Page-" + this.Frame.BackStackDepth;
        if (e.NavigationMode == NavigationMode.New)
        {
            var nextPageKey = this._pageKey;
            int nextPageIndex = this.Frame.BackStackDepth;
            while (frameState.Remove(nextPageKey))
            {
                nextPageIndex++;
                nextPageKey = "Page-" + nextPageIndex;
            }
            if (this.LoadState != null)
            {
                this.LoadState(this, new LoadStateEventArgs(e.Parameter, null));
            }
        }
        else
        {
            if (this.LoadState != null)
            {
                this.LoadState(this, new LoadStateEventArgs(e.Parameter, (Dictionary<String, Object>)frameState[this._pageKey]));
            }
        }
    }
    
    看,它们是一样的。它们之间没有什么不同,只是执行管道可能会稍微影响计时,但不太可能。最后,没有真正的区别。需要使用其中一个而不是另一个的人。。。他们一定是弄错了,把原因归咎于其他因素的影响


    祝你好运。

    我的问题或多或少与此类似,只有在使用loadstate而不是navigationHelper\u loadstate时,我的代码才会起作用。
    private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {
        LoadState(e);
    }
    
    private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
    {
        SaveState(e);
    }
    
    protected virtual void LoadState(LoadStateEventArgs e) { }
    protected virtual void SaveState(SaveStateEventArgs e) { }