【问题标题】:Windows phone pass selected parameter from listview item to other pageWindows phone 将列表视图项中的选定参数传递到其他页面
【发布时间】:2015-04-20 15:32:28
【问题描述】:

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

我的班级

-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 ?

    }

【问题讨论】:

    标签: c# wpf visual-studio listview windows-phone-8.1


    【解决方案1】:

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

    将以下代码添加到 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;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      • 2016-12-24
      • 2013-05-11
      • 2023-03-14
      • 1970-01-01
      相关资源
      最近更新 更多