![](/img/trans.png)
[英]Unable to navigate the page in FrayxRulez/SwipeListView control in windows phone 8.1
[英]Unable to navigate to another page on button click in windows phone 8.1
我有一個按鈕,單擊它后,我需要轉到另一個xaml頁面。
此按鈕位於Page1.xaml中
<Button Content="Button Name" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Button_Click" Foreground="#FF119FF0"/>
private void Button_Click(object sender, RoutedEventArgs e)
{
frameBody.Navigate(typeof(HomePage));
}
但是我無法導航到HomePage.xaml。
可能是什么原因?
這些是我包括的庫:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
Page1.xaml.cs中定義了功能Button_Click()。
我認為您缺少指令或程序集引用?
用於Windows Phone 8.1導航
Frame.Navigate(typeof(Urpage));
對於窗口電話8.0
NavigationService.Navigate(new Uri("/URpage.xaml", UriKind.Relative));
檢查您是否正在使用Windows Phone sliverlight項目,並且您的班級正在像這樣擴展/繼承“ PhoneApplicationPage”:
public partial class Example : PhoneApplicationPage
{
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Homepage.xaml", UriKind.RelativeOrAbsolute));
}
}
希望這可以幫助
這是我在項目中使用的代碼:
private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
var albumId = ((Album)e.ClickedItem).Id;
if (!Frame.Navigate(typeof(AlbumPage), albumId))
{
var resourceLoader = ResourceLoader.GetForCurrentView("Resources");
throw new Exception(resourceLoader.GetString("NavigationFailedExceptionMessage"));
}
}
要關注的部分是Frame.Navigate(typeof(AlbumPage))
。
我想向該頁面傳遞一些信息,這就是為什么我傳遞我的albumId
的原因。
如果要檢索其他頁面中傳遞的參數,則可能需要使用以下代碼:
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
var albumId = (int)e.NavigationParameter;
}
注意的另一個最重要的一點是,您可能需要檢查“ App.xaml.cs”文件,然后在OnLaunched方法中更改
rootFrame.Navigate(typeof(UrPage),e.Arguments);
默認情況下,MainPage.xaml加載。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.