Windows phone 将所选参数从列表视图项传递到其他页面

Windows phone pass selected parameter from listview item to other page

我制作了 Windows phone 8.1 应用程序来显示某些事件。它向我显示图片、标题、位置和活动 ID。所有这些事件都显示在列表视图中。现在我想点击指定的事件并在新页面上显示事件描述。任何人都知道如何检查在列表视图中点击了哪个事件并在新页面中显示他的描述(BlankPage1.xaml)?

我的class

-FSfeed.cs

public class Rootobject
{
    public Class1[] Property1 { get; set; }
}

public class Class1
{
    public string id { get; set; }
    public string title { get; set; }
    public string description { get; set; }
    public string image { get; set; }
    public string start { get; set; }
    public string end { get; set; }
    public string location { get; set; }
}

正在列表视图中显示事件

-StartPage.xaml

            <Grid HorizontalAlignment="Left" Height="538" VerticalAlignment="Top" Width="400">
                <ListView x:Name="Reviews" Margin="0,0,0,0" Grid.Row="1" >
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="110" Height="110">
                                    <Image Source="{Binding image}" Stretch="UniformToFill" />

                                </Border>
                                <TextBlock Text=" " />
                                <StackPanel x:Name="st1" Grid.Column="1" VerticalAlignment="Top" Orientation="Vertical" Margin="10,0,0,0" >
                                    <TextBlock Text="{Binding title}" TextWrapping="Wrap"/>
                                    <StackPanel Grid.Column="1" VerticalAlignment="Top" Orientation="Horizontal" Margin="0,0,0,0">
                                        <TextBlock Margin="10,0,0,0" Text="Location:" FontWeight="Bold"/>
                                        <TextBlock Margin="10,0,0,0" Text="{Binding location}"/>
                                    </StackPanel>
                                    <StackPanel Grid.Column="1" VerticalAlignment="Top" Orientation="Horizontal" Margin="0,0,0,0">
                                        <TextBlock Margin="10,0,0,0" Text="Start:" FontWeight="Bold"/>
                                        <TextBlock Margin="10,0,0,0" Text="{Binding start}"/>
                                    </StackPanel>
                                    <StackPanel Grid.Column="1" VerticalAlignment="Top" Orientation="Horizontal" Margin="0,0,0,0">
                                        <TextBlock Margin="10,0,0,0" Text="Id:" FontWeight="Bold"/>
                                        <TextBlock Margin="10,0,0,0" Text="{Binding id}"/>
                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Grid>

点击列表视图项时将用户导航到新页面 (BlankPage1)

-StartPage.xaml.cs

    private void Reviews_Tapped(object sender, TappedRoutedEventArgs e)
    {
        this.Frame.Navigate(typeof(BlankPage1));

        //check which event has been tapped and show his description on BlankPage1.xaml ?

    }

好的,经过几个小时的研究我找到了答案...

将以下代码添加到StartPage.xaml.cs

    private void Reviews_Tapped(object sender, TappedRoutedEventArgs e)
    {

        Class1 myobject = Reviews.SelectedItem as Class1;

        Frame.Navigate(typeof(BlankPage1), myobject);

    }

然后在目标页面 (BlankPage1) 上创建文本块并添加以下代码:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var myObject = (Class1) e.Parameter;
        textblock.Text = myObject.title;
    }