private void WebResponseCallback(IAsyncResult result) { JSearch[] jSearchs; try { HttpWebRequest request = ((HttpWebRequest)result.AsyncState); StreamReader sr = new StreamReader(request.EndGetResponse(result).GetResponseStream()); string data = sr.ReadToEnd(); jSearchs = JsonConvert.DeserializeObject<JSearch[]>(data); } catch { jSearchs = new JSearch[0]; } CallbackMethod(jSearchs); }
private void Update(JSearch[] jSearchs) { Dispatcher.BeginInvoke(() => { String showMessage =""; for (int i = 0; i < jSearchs.Length; i++) { showMessage += i + "\n"; showMessage += "url: " + jSearchs[i].URL + "\n"; showMessage += "source: " + jSearchs[i].Source + "\n"; showMessage += "price: " + jSearchs[i].Price + "\n"; showMessage += "img: " + jSearchs[i].Img + "\n"; showMessage += "title: " + jSearchs[i].Title + "\n"; } MessageBox.Show(showMessage); }); }
private void SearchData(JSearch[] jSearchs) { Dispatcher.BeginInvoke(() => { contentStackPanel.Children.Clear(); if (jSearchs.Length == 0) contentStackPanel.Children.Add(fileNotFound()); for (int i = 0; i < jSearchs.Length; i++) contentStackPanel.Children.Add(createlistview(jSearchs[i])); }); }
private Grid createlistview( JSearch jSearchs) { Grid item = new Grid(); item.Name = jSearchs.URL; item.Height = 150; item.Tap += item_Tap; //new and set value TextBlock title = new TextBlock(); TextBlock source = new TextBlock(); TextBlock price = new TextBlock(); Image image = new Image(); title.Text = jSearchs.Title; source.Text = jSearchs.Source; price.Text ="$"+ jSearchs.Price; image.Source = new BitmapImage(new Uri(jSearchs.Img, UriKind.RelativeOrAbsolute)); //set font title.FontWeight = FontWeights.Bold; source.FontSize = 19; title.FontSize = 30; price.FontSize = 50; price.Foreground = new SolidColorBrush(Colors.Red); source.Foreground = new SolidColorBrush(Colors.Orange); title.TextWrapping = TextWrapping.Wrap;//換行 //設定邊界長寬 title.Margin = new Thickness(110, 0, 0, 0); source.Margin = new Thickness(110, 110, 0, 0); price.Margin = new Thickness(0, 0, 1, 0); image.Width = 100; image.Height = 100; title.Height = 40 * 2; title.Width = item.Width; price.Width = item.Width; //設定對齊 image.HorizontalAlignment = HorizontalAlignment.Left; title.HorizontalAlignment = HorizontalAlignment.Left; source.HorizontalAlignment = HorizontalAlignment.Left; price.HorizontalAlignment = HorizontalAlignment.Right; title.VerticalAlignment = VerticalAlignment.Top; image.VerticalAlignment = VerticalAlignment.Top; price.VerticalAlignment = VerticalAlignment.Bottom; image.VerticalAlignment = VerticalAlignment.Center; item.Margin = new Thickness(0, 20, 0, 0); //最後add進去 item.Children.Add(image); item.Children.Add(title); item.Children.Add(source); item.Children.Add(price); item.Children.Add(drawLine()); return item; }