0

我正在获取数据来创建一个类似于博客的列表框,其中包含来自网络博客的 JSON,我想在您选择一个项目时将此数据传递到另一个包含此新闻信息(标题、内容和图像)的简单 xaml 页面。如何使用列表中所选项目的信息获取新页面的所有值?

我有这个列表框的代码:

            <ListBox x:Name="NewsList" Margin="0,200,0,0" ItemsSource="{Binding Items}" SelectionChanged="ListBox_SelectionChanged">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="0,0,0,17" Width="432" Height="100">
                                <!--Replace rectangle with image-->
                                <Image x:Name="Imagen" Height="100" Width="100"  Margin="12,0,9,0">
                                    <Image.Source>
                                        <BitmapImage UriSource="{Binding LineThree}" />
                                    </Image.Source>
                                </Image>
                                <StackPanel Width="311">
                                    <TextBlock x:Name="Titulo" Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="18.667" FontFamily="Tahoma" Margin="12,0,12,6"/>
                                    <TextBlock x:Name="Contenido" Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,0" Style="{StaticResource PhoneTextSubtleStyle}" FontSize="16"/>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

我从这里的新闻中获取值:项目是我添加新闻值的列表(标题、内容和图像)

 public void LoadData()
    {
        WebRequest.RegisterPrefix("http://automaticband.es/blog/", WebRequestCreator.ClientHttp);
        Uri serviceUri = new Uri("http://automaticband.es/blog/?json=get_recent_post");
        WebClient downloader = new WebClient();
        downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
        downloader.OpenReadAsync(serviceUri);
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            try
            {
                Stream responseStream = e.Result;
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Posts));
                Posts response = (Posts)ser.ReadObject(responseStream);
                if (response.posts != null && response.posts.Count > 0)
                {
                    foreach (Post post in response.posts)
                    {

                        this.Items.Add(new ItemViewModel() { LineOne = post.title, LineTwo = post.excerpt,
                            LineThree = post.thumbnail});
                    }
                }
            }
            catch (Exception x)
            {
                return;
            }
            this.IsDataLoaded = true;
        }
    }

谢谢

4

1 回答 1

0

我在这里找到了解决方案:

http://windowsphonegeek.com/articles/Windows-Phone-MVVM-Master---Details-Navigation-in-5-minutes

使用 ItemViewModel 在页面之间传递数据的简单方法。

于 2013-01-04T02:28:29.487 回答