/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> /* protected override void OnNavigatedTo(NavigationEventArgs e) * { * // Check if ExtendedSplashscreen.xaml is on the backstack and remove * if (Frame.BackStack.Count() == 1) * { * Frame.BackStack.RemoveAt(Frame.BackStackDepth - 1); * } * base.OnNavigatedTo(e); * }*/ private async void AppBarButton_Click(object sender, RoutedEventArgs e) { if (IsInternetAvailable) { feedStatus = FindChildControl <TextBlock>(NewsHubSection, "feedStatus") as TextBlock; statusPanel = FindChildControl <StackPanel>(NewsHubSection, "statusPanel") as StackPanel; response = new HttpResponseMessage(); // if 'feedAddress' value changed the new URI must be tested -------------------------------- // if the new 'feedAddress' doesn't work, 'feedStatus' informs the user about the incorrect input. feedStatus.Text = "Test if URI is valid"; Uri resourceUri; if (!Uri.TryCreate(feedAddress.Trim(), UriKind.Absolute, out resourceUri)) { feedStatus.Text = "Invalid URI, please re-enter a valid URI"; return; } if (resourceUri.Scheme != "http" && resourceUri.Scheme != "https") { feedStatus.Text = "Only 'http' and 'https' schemes supported. Please re-enter URI"; return; } // ---------- end of test--------------------------------------------------------------------- string responseText; feedStatus.Text = "Waiting for response ..."; try { response = await httpClient.GetAsync(resourceUri); response.EnsureSuccessStatusCode(); responseText = await response.Content.ReadAsStringAsync(); statusPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } catch (Exception ex) { // Need to convert int HResult to hex string feedStatus.Text = "Error = " + ex.HResult.ToString("X") + " Message: " + ex.Message; responseText = ""; } feedStatus.Text = response.StatusCode + " " + response.ReasonPhrase; // now 'responseText' contains the feed as a verified text. // next 'responseText' is converted as the rssItems class model definition to be displayed as a list List <rssItems> lstData = new List <rssItems>(); XElement _xml = XElement.Parse(responseText); XNamespace content = "URI"; foreach (XElement value in _xml.Elements("channel").Elements("item")) { rssItems _item = new rssItems(); _item.title = value.Element("title").Value; _item.description = value.Element("description").Value; _item.link = value.Element("link").Value; // _item.enclosure = value.Element("enclosure").Value; string url = (string)value.Element("enclosure").Attribute("url"); _item.url = url; lstData.Add(_item); } // lstRSS is bound to the lstData: the final result of the RSS parsing lstRSS = FindChildControl <ListView>(NewsHubSection, "lstRSS") as ListView; lstRSS.DataContext = lstData; } else { //MessageBox("Internet connectivity is required with this fonctionnality"); StandardPopup = FindChildControl <Popup>(NewsHubSection, "StandardPopup") as Popup; if (!StandardPopup.IsOpen) { StandardPopup.IsOpen = true; } } }
private async void GridView_Loaded(object sender, RoutedEventArgs e) { /*ListEntite = new List<Entite>(); * ListEntite.Add(new Entite() { title = "Premier article", image = "/Assets/ecv.jpg", description = "Attentat fomenté par les services secrets, coup monté des medias, manigance des ennemis de l'islam... Le 7 janvier 2015, les théories conspirationnistes censées élucider l'attentat meurtrier contre Charlie Hebdo n'ont mis que quelques heures à se répandre sur internet. Comment reconnaître et lutter contre ces explications fantasques ? ➜ A lire également : Où sont passés les paranos ? ➜ Dossier web : Qu'est-ce que la rumeur ?" }); * ListEntite.Add(new Entite() { title = "Deuxième article", image = "/Assets/1735236-fleur-pellerin-se-dote-d-une-commission-de-terminologie-de-l-economie-numerique.jpg", description = "Attentat fomenté par les services secrets, coup monté des medias, manigance des ennemis de l'islam... Le 7 janvier 2015, les théories conspirationnistes censées élucider l'attentat meurtrier contre Charlie Hebdo n'ont mis que quelques heures à se répandre sur internet. Comment reconnaître et lutter contre ces explications fantasques ? ➜ A lire également : Où sont passés les paranos ? ➜ Dossier web : Qu'est-ce que la rumeur ?" }); * ListEntite.Add(new Entite() { title = "Troisième Article", image = "/Assets/economie3.jpg", description = "Attentat fomenté par les services secrets, coup monté des medias, manigance des ennemis de l'islam... Le 7 janvier 2015, les théories conspirationnistes censées élucider l'attentat meurtrier contre Charlie Hebdo n'ont mis que quelques heures à se répandre sur internet. Comment reconnaître et lutter contre ces explications fantasques ? ➜ A lire également : Où sont passés les paranos ? ➜ Dossier web : Qu'est-ce que la rumeur ?" }); * ListEntite.Add(new Entite() { title = "Premier article", image = "/Assets/statistique.jpg", description = "Attentat fomenté par les services secrets, coup monté des medias, manigance des ennemis de l'islam... Le 7 janvier 2015, les théories conspirationnistes censées élucider l'attentat meurtrier contre Charlie Hebdo n'ont mis que quelques heures à se répandre sur internet. Comment reconnaître et lutter contre ces explications fantasques ? ➜ A lire également : Où sont passés les paranos ? ➜ Dossier web : Qu'est-ce que la rumeur ?" }); * * var list = sender as GridView; * * list.DataContext = ListEntite;*/ if (IsInternetAvailable) { //feedStatus = FindChildControl<TextBlock>(NewsHubSection, "feedStatus") as TextBlock; // statusPanel = FindChildControl<StackPanel>(NewsHubSection, "statusPanel") as StackPanel; response = new HttpResponseMessage(); // if 'feedAddress' value changed the new URI must be tested -------------------------------- // if the new 'feedAddress' doesn't work, 'feedStatus' informs the user about the incorrect input. // feedStatus.Text = "Test if URI is valid"; Uri resourceUri; if (!Uri.TryCreate(feedAddress.Trim(), UriKind.Absolute, out resourceUri)) { // feedStatus.Text = "Invalid URI, please re-enter a valid URI"; return; } if (resourceUri.Scheme != "http" && resourceUri.Scheme != "https") { // feedStatus.Text = "Only 'http' and 'https' schemes supported. Please re-enter URI"; return; } // ---------- end of test--------------------------------------------------------------------- string responseText; // feedStatus.Text = "Waiting for response ..."; try { response = await httpClient.GetAsync(resourceUri); response.EnsureSuccessStatusCode(); responseText = await response.Content.ReadAsStringAsync(); // statusPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } catch (Exception ex) { // Need to convert int HResult to hex string // feedStatus.Text = "Error = " + ex.HResult.ToString("X") + //" Message: " + ex.Message; responseText = ""; } // feedStatus.Text = response.StatusCode + " " + response.ReasonPhrase; // now 'responseText' contains the feed as a verified text. // next 'responseText' is converted as the rssItems class model definition to be displayed as a list List <rssItems> lstData = new List <rssItems>(); XElement _xml = XElement.Parse(responseText); XNamespace content = "URI"; foreach (XElement value in _xml.Elements("channel").Elements("item")) { rssItems _item = new rssItems(); _item.title = value.Element("title").Value; _item.description = value.Element("description").Value; _item.link = value.Element("link").Value; // _item.enclosure = value.Element("enclosure").Value; string url = (string)value.Element("enclosure").Attribute("url"); _item.url = url; lstData.Add(_item); } // lstRSS is bound to the lstData: the final result of the RSS parsing // lstRSS = FindChildControl<ListView>(NewsHubSection, "lstRSS") as ListView; var list = sender as GridView; list.DataContext = lstData; } }