2013-01-04 87 views
0

我正在從Webblog獲取數據以創建一個帶有JSON的博客的列表框,我想在選擇一個項目時將此數據傳遞到另一個簡單的xaml頁面,並顯示此信息新聞(標題,內容和圖片)。如何使用列表中所選項目的信息獲取新頁面的所有值?從列表框導航中傳遞數據Windows Phone

我有一個列表框下面的代碼:

  <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; 
     } 
    } 

謝謝

回答