-1

我尝试做一个全景应用程序,当您点击列表框中的项目时,它会打开一个新页面。所以列表框由一个图像和一个 texbox 组成,然后我点击我想将图像的名称带入新页面。有什么建议吗??(对不起,我的英语不好)

4

2 回答 2

1

尝试:

               <ListBox ItemsSource="{Binding Items}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <Image Source="{Binding ImageUrl}" Tag="{Binding ImageName}" Tap="Image_Tap"/>
                                <TextBlock Text="{Binding Text}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

在后面的代码中

private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
   Image img = sender as Image;
   String name = img.Tag.ToString();
   NavigationService.Navigate(new Uri("Page2.xaml?ImageName="+name,UriKind.Relative));
}

在 Page2.xaml.cs 上

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        String Name = NavigationContext.QueryString["ImageName"];
        base.OnNavigatedTo(e);
    }
于 2012-09-28T14:06:06.423 回答
0

您可以传递参数,如本例所示。

因此,在 Tap 事件中,您需要获取图像名称,将其保存到任何字符串并作为查询参数传递:

var url = "/Views/PageName.xaml?imageName=" + imageName;
NavigationService.Navigate(new Uri(url ,UriKind.Relative));
于 2012-09-28T14:03:27.617 回答