导航控制(使用功能)

时间:2012-01-17 14:15:01

标签: windows-phone-7

我的问题与我在这里看过的例子略有不同。

我在每个页面上都有一个导航用户控件。 在一个典型的页面上,我有我的按钮点击事件。

private void butArtists_Click(object sender, RoutedEventArgs e)
    {           
        PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
        MainPage mp = frame.Content as MainPage;
        mp.PlayerMenu("Artists");
    }

当我在MainPage.xaml上时,代码工作正常。但是,当我在pgArtists上时,没有任何事情发生。我假设正在发生的是页面已设置但未显示。

我在上面的函数和类似函数上设置了断点。我是对的吗?

所以问题是,当用户控件嵌入到pgArtists中时,帧内容不会回滚到MainPage。

2 个答案:

答案 0 :(得分:1)

这不是Windows Phone上页面导航的工作原理。请查看“How to: Perform Page Navigation on Windows Phone link on MSDN”。

您应该使用每个页面提供的NavigationService,而不是直接摆弄PhoneApplicationFrame。

答案 1 :(得分:0)

从任何页面使用类似的内容:

var uriFragment = @"views/ArtistsView.xaml";
(App.Current.RootVisual as Frame).Navigate(new Uri(uriFragment, UriKind.Relative));