[英]UWP Overriding Frame.Navigate to pass data from ListViewItem to new Page casues Null Exception
I have this XAML ListViewItem: 我有这个XAML ListViewItem:
<ListView HorizontalAlignment="Center" Height="500" Margin="0,130,0,0"
VerticalAlignment="Top" Width="400" x:Name="RoutesListView"
SelectionChanged="RoutesListView_SelectionChanged"
IsItemClickEnabled="True" SelectionMode="Single"
ItemClick="RoutesListView_ItemClick">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel >
<TextBlock Text="{Binding RouteName}"
Margin="20,0,20,8"
FontFamily="Calibri"
FontSize="24
FontWeight="SemiBold"
Foreground="Gray"
/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
In the click-handler I want to send the Route object's ID to a new page like this: 在点击处理程序中,我想将Route对象的ID发送到新页面,如下所示:
private void RoutesListView_ItemClick(object sender, ItemClickEventArgs e)
{
var items = (sender as ListView).Items;
var route = items[index] as Route;
var id = route.ID;
var data = new RouteParameters { ID = id };
Frame.Navigate(typeof(RouteView), data);
}
The RouteParameters class looks like this: RouteParameters类如下所示:
public class RouteParameters
{
public int ID { get; set; }
}
Finally in the RouteView I override the OnNavigatedTo like this: 最后,在RouteView中,我像这样重写OnNavigatedTo:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var p = e.Parameter as RouteParameters;
int id = p.ID;
}
I get a Null exception in the Frame.Navigate method. 我在Frame.Navigate方法中得到一个Null异常。 Sorry if I missed something obvious but I can't find out what is causing the error after debugging every line and not seeing any null object
抱歉,如果我错过了明显的事情,但是在调试每一行并且看不到任何空对象之后,我无法找出导致错误的原因
Okay, so I found out that I had previously added a parameter to the RouteView class and forgotten to remove it while trying different methods of passing data to the new view. 好的,所以我发现我之前已经向RouteView类添加了一个参数,却忘记了在尝试将数据传递到新视图的其他方法时将其删除。 This is not a problem anymore and I will close the thread in 48 hours.
这不再是问题,我将在48小时内关闭该线程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.