usercontrol执行页面跳转

来源:互联网 发布:淘宝偏远地区 编辑:程序博客网 时间:2024/06/08 05:01

(一、一般的页面跳转)

XAML

<HyperlinkButton NavigateUri="SecondPage.xaml" />

C# for MainPage.xaml.cs

private void MyButton_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/SecondPage.xaml",
UriKind.RelativeOrAbsolute));
}

C# for SecondPage.xaml.cs

private void BtnBack_Click(object sender, RoutedEventArgs e)
{
if (NavigationService.CanGoBack)
NavigationService.GoBack();
}
传参数

C# for MainPage.xaml.cs

private void MyButton_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/SecondPage.xaml?msg=" +
MyTB.Text, UriKind.RelativeOrAbsolute));
}

C# for SecondPage.xaml.cs

protected override void OnNavigatedTo
(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string msg = "";
if (NavigationContext.QueryString.TryGetValue("msg", out msg))
MyTBl.Text = msg;
}
(二、通过App.Current.RootVisual

App app=Application.Current as App;
app.RootVisual=new older_homepage();


var root = App.Current.RootVisual as PhoneApplicationFrame;
 root.Navigate(new Uri("/older/older_homepage.xaml", UriKind.RelativeOrAbsolute));







原创粉丝点击