我哪里出错了?
private void lstCars_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string currCar = (sender as ListBox).SelectedItem as string;
NavigationService.Navigate(new Uri("/ViewCarDetails.xaml?info=" + currCar, UriKind.Relative));
}
这是我尝试导航到的页面
public ViewCarDetails(string registrationNum)
{
//stuff
}
这是我收到错误时程序跳转到的代码(在 App.xaml.cs 中)
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
我检查了URI,但没有错别字谢谢
问题是您正在通过导航服务传递参数,而 ViewCarDetails 类构造函数需要您没有传递的参数。
要解决这个问题,您必须创建一个没有参数的构造函数,并从 NavigatedTo 事件获取您通过导航服务传递的参数,如下所示:
public ViewCarDetails()
{
//stuff
}
和
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string registrationNum = string.Empty;
if (NavigationContext.QueryString.TryGetValue("index", out registrationNum))
{
//do stuff
}
}
尝试一下,让我们知道,
添加:
public class ViewCarDetails : PhoneApplicationPage
{
private string registrationNum;
public ViewCarDetails()
{
//stuff
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
registrationNum = string.Empty;
if (NavigationContext.QueryString.TryGetValue("index", out registrationNum))
{
//do stuff
}
}
//other methods and properties
}
问候