Windows Phone 7导航传递参数
本文关键字:参数 导航 Phone Windows | 更新日期: 2023-09-27 18:21:04
我有一个如下的列表框。
<ListBox x:Name="CouponListBox" ItemsSource="{Binding Item}" SelectionChanged="CouponListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding MerchantImage}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
<StackPanel Width="130">
<TextBlock Text="{Binding CustomerName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding MerchantName}" TextWrapping="Wrap" FontSize="20" Foreground="#FFC4C4C4" Padding="10" />
<TextBlock Text="{Binding Distance}" TextWrapping="Wrap" FontSize="16" Foreground="#FFC4C4C4" Padding="10" />
<TextBlock Text="{Binding DistanceInMinutes}" TextWrapping="Wrap" FontSize="16" Foreground="#FFC4C4C4" Padding="10" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我在.cs文件中有一个更改事件,它是
private void CouponListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// If selected index is -1 (no selection) do nothing
if (CouponListBox.SelectedIndex == -1)
return;
// Navigate to the new page
System.Diagnostics.Debug.WriteLine("this is a test::" + CouponListBox.SelectedItem.ToString());
NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + CouponListBox.SelectedIndex, UriKind.Relative));
// Reset selected index to -1 (no selection)
CouponListBox.SelectedIndex = -1;
}
在DetailsPage中,我可以打印项目索引。但我想要的是像一样在URL中传递客户ID
"/DetailsPage.xaml?selectedItem=" + CouponListBox.SelectedIndex + "&customerId=" + couponId
有人能告诉我在XAML文件中应该在哪里包含customerId吗?以及我在函数中可以称之为谁。
谢谢,Karthik
使用此:
if (this.NavigationContext.QueryString.ContainsKey("customerId"))
{
string customerId = this.NavigationContext.QueryString["customerId"];
}
if (this.NavigationContext.QueryString.ContainsKey("selectedItem"))
{
string selectedItem = this.NavigationContext.QueryString["selectedItem"];
}
在用户控件的Loaded或其他适当的事件中。