单击列表视图项目发送到另一页面

时间:2015-07-07 14:59:28

标签: c# list xaml view windows-phone

我有这样的事情:

enter image description here

XAML(对于一个项目):

  <ListView Margin="10,0,10,10" Width="360" Height="510" VerticalAlignment="Bottom" RenderTransformOrigin="0.479,0.497">
            <ListViewItem RenderTransformOrigin="0.719,0.534">
                <StackPanel Orientation="Horizontal">
                    <Image Source="/Assets/1.png" Margin="0,0,5,0" />
                    <TextBlock FontSize="20" Width="302" RenderTransformOrigin="0.698,0.49" SelectionChanged="TextBlock_SelectionChanged" IsHoldingEnabled="False" IsDoubleTapEnabled="False">
                        <Run Text="Stotis–Oro uostas"/>
                    </TextBlock>

C#:

private void TextBlock_SelectionChanged(object sender, RoutedEventArgs e)
    {
       this.Frame.Navigate(typeof(SecondPage));
    }

我想这样做:当我点击第一项时,它应该将我发送到另一页。

1 个答案:

答案 0 :(得分:0)

您必须将tapped侦听器添加到listview项目,如下所示:

 <ListView Margin="10,0,10,10" Width="360" Height="510" VerticalAlignment="Bottom" RenderTransformOrigin="0.479,0.497">
        <ListViewItem x:Name="ListViewItem1" Tapped="ListViewItem1_Tapped">
            <!--add your image and text and ...-->
        </ListViewItem>
        <ListViewItem x:Name="ListViewItem2" Tapped="ListViewItem2_Tapped">
            ...
        </ListViewItem>
        <ListViewItem x:Name="ListViewItem3" Tapped="ListViewItem3_Tapped">
            ...
        </ListViewItem>
    </ListView>

您可以在文件后面添加代码:

private void ListViewItem1_Tapped(object sender, TappedRoutedEventArgs e)
    {
        this.Frame.Navigate(typeof(FirstPage));
    }

    private void ListViewItem2_Tapped(object sender, TappedRoutedEventArgs e)
    {
        this.Frame.Navigate(typeof(SecondPage));
    }

    private void ListViewItem3_Tapped(object sender, TappedRoutedEventArgs e)
    {
        this.Frame.Navigate(typeof(ThirdPage));
    }

我希望这就像你想要的那样。