ScrollView Frame.Navigate Null

时间:2012-09-02 23:54:50

标签: xaml windows-8 microsoft-metro

我正在尝试从ScrollViewer控件导航到页面:

  <Button x:Name="btnViewMenu" Content="View Menu" Click="btnViewMenu_Click" Margin="0,20,0,0" CommandParameter="{Binding}" Grid.Row="3" />

 private void btnViewMenu_Click(object sender, RoutedEventArgs e)
    {
        Button btn = (Button)sender;
        RestaurantLocation loc = btn.CommandParameter as RestaurantLocation;
        App.CurrentRestaurantLocation = loc;
        this.Frame.Navigate(typeof(SearchFormPage));
    }

在搜索表单页面上,我收到此错误:

_pageKey不能为null:

    /// <summary>
    /// Invoked when this page will no longer 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 OnNavigatedFrom(NavigationEventArgs e)
    {
        var frameState = SuspensionManager.SessionStateForFrame(this.Frame);
        var pageState = new Dictionary<String, Object>();
        this.SaveState(pageState);
        frameState[_pageKey] = pageState;
    }

我导航不正确吗?这只发生在滚动查看器中。

2 个答案:

答案 0 :(得分:0)

感谢。我不得不调用基本方法:

 protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        List<string> theResults = e.Parameter as List<string>;
        city = theResults[0];
        state = theResults[1];
        category = theResults[2];
        BindData();
    }

答案 1 :(得分:0)

确保你是一个呼叫基地.OnNavigatedTo(e)和base.OnNavigatedFrom(e)

在执行逻辑后的覆盖方法中