2014-02-08 32 views
0

我建立了Windows Phone 7的地方我是從Web服務收集一些數據的應用程序,並在一個列表框顯示這些數據作爲參數發送列表框接收的圖像。現在點擊列表框中的一個項目,我將其導航到另一個頁面,在那裏顯示完整的細節。 在列表框中顯示項目的代碼是:如何顯示從下頁

public class Newss 
{ 
    public string News_Title { get; set; } 
    public string News_Description { get; set; } 
    public string Date_Start { get; set; } 
    public string image_path { get; set; } 
    public BitmapImage ImageBind{get;set;} 
} 

public News() 
{ 
    InitializeComponent(); 

    KejriwalService.aapSoapClient client = new KejriwalService.aapSoapClient(); 
    client.getarvindNewsCompleted += new EventHandler<KejriwalService.getarvindNewsCompletedEventArgs>(client_getarvindNewsCompleted); 
    client.getarvindNewsAsync(); 

    progressName.Visibility = System.Windows.Visibility.Visible; 
} 

void client_getarvindNewsCompleted(object sender, KejriwalService.getarvindNewsCompletedEventArgs e) 
{ 
    string result = e.Result.ToString(); 
    List<Newss> listData = new List<Newss>(); 
    XDocument doc = XDocument.Parse(result); 

    progressName.Visibility = System.Windows.Visibility.Collapsed; 

    foreach (var location in doc.Descendants("UserDetails"))   
    { 
     Newss data = new Newss(); 

     data.News_Title = location.Element("News_Title").Value; 
     data.News_Description = location.Element("News_Description").Value; 
     data.Date_Start = location.Element("Date_Start").Value; 
     data.image_path = location.Element("image_path").Value; 
     data.ImageBind = new BitmapImage(new Uri(@"http://political-leader.vzons.com/ArvindKejriwal/images/uploaded/"+data.image_path, UriKind.Absolute)); 

     listData.Add(data); 
    } 

    listBox1.ItemsSource = listData; 
} 

我正在將數據發送到下一個頁面的方法是:

private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    // If selected index is -1 (no selection) do nothing 

    if (listBox1.SelectedIndex == -1) 
     return; 

    Newss news = listBox1.SelectedItem as Newss; 
    NavigationService.Navigate(new Uri("/NewsDetails.xaml?News_Title=" + news.News_Title + "&News_Description=" + news.News_Description +"&Date_Start=" +news.Date_Start + "&image_path=" + news.image_path, UriKind.Relative)); 

    // Reset selected index to -1 (no selection) 
    listBox1.SelectedIndex = -1; 
} 

現在我能夠在接下來的頁面中顯示news_title,news_description,date_start,但無法顯示圖像。我在頁面代碼:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 
    var imagePath = ""; 
    var dateStart = ""; 
    var newsTitle = ""; 
    var newsDescription = ""; 

    if (this.NavigationContext.QueryString.ContainsKey("Date_Start")) 
    { 
     //if it is available, get parameter value 
     dateStart = NavigationContext.QueryString["Date_Start"]; 
     date.Text = dateStart; 
    } 

    if (this.NavigationContext.QueryString.ContainsKey("News_Title")) 
    { 
     //if it is available, get parameter value 
     newsTitle = NavigationContext.QueryString["News_Title"]; 
     title.Text = newsTitle; 
    } 

    if (this.NavigationContext.QueryString.ContainsKey("News_Description")) 
    { 
     //if it is available, get parameter value 
     newsDescription = NavigationContext.QueryString["News_Description"]; 

     description.Text = newsDescription; 
    }    
} 

請幫助我的人,以顯示在下面

我的XAML給出了顯示圖像的XAML中NewsDetails頁面的圖像是:

<Image Height="201" HorizontalAlignment="Left" Margin="45,113,0,0" Name="newsimage" Stretch="Fill" VerticalAlignment="Top" Width="368" /> 

回答

1

看看你在前一頁顯示圖像的方式,我認爲這樣的事情會起作用:

var imagePath = ""; 
if (this.NavigationContext.QueryString.ContainsKey("image_path")) 
{ 
    imagePath = NavigationContext.QueryString["image_path"]; 
    newsimage.Source = new BitmapImage(new Uri(@"http://political-leader.vzons.com/ArvindKejriwal/images/uploaded/"+imagePath, UriKind.Absolute)); 
} 

我認爲在Uri中傳遞的「image_path」參數包含前一頁的值data.image_path