Autor |
Beitrag |
martinklaus
Hält's aus hier
Beiträge: 5
|
Verfasst: So 31.08.14 11:35
Hallo
ich bin ganz neu und das ist meine erste Windows 8 app.
Ich ha probleme mit dem List.First() methode.
Die Basis ist eine Windows 8 Raster app.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131:
| using DotnetBlogApp.Common; using DotnetBlogApp.Data; using System; using System.Collections.Generic; using System.IO; using System.Linq; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation;
namespace DotnetBlogApp { public sealed partial class GroupedItemsPage : Page { private NavigationHelper navigationHelper; private ObservableDictionary defaultViewModel = new ObservableDictionary();
public NavigationHelper NavigationHelper { get { return this.navigationHelper; } }
public ObservableDictionary DefaultViewModel { get { return this.defaultViewModel; } }
public GroupedItemsPage() { this.InitializeComponent(); this.navigationHelper = new NavigationHelper(this); this.navigationHelper.LoadState += navigationHelper_LoadState; }
private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) {
BlogFeedProxy blogFeedProxy = new BlogFeedProxy(); var feeds = await blogFeedProxy.LoadFeedsAsync();
this.DefaultViewModel["Groups"] = feeds; }
void Header_Click(object sender, RoutedEventArgs e) { var group = (sender as FrameworkElement).DataContext;
this.Frame.Navigate(typeof(GroupDetailPage), ((SampleDataGroup)group).UniqueId); }
void ItemView_ItemClick(object sender, ItemClickEventArgs e) { var itemId = ((SampleDataItem)e.ClickedItem).UniqueId; this.Frame.Navigate(typeof(ItemDetailPage), itemId); }
#region NavigationHelper-Registrierung
protected override void OnNavigatedTo(NavigationEventArgs e) { navigationHelper.OnNavigatedTo(e); }
protected override void OnNavigatedFrom(NavigationEventArgs e) { navigationHelper.OnNavigatedFrom(e); }
#endregion
public object feeds { get; set; } } } |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42:
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DotnetBlogApp.Data; using Windows.Web.Syndication; using DotnetBlogApp.Common;
namespace DotnetBlogApp { public class BlogFeedProxy { public async Task<IEnumerable<SampleDataGroup>> LoadFeedsAsync() { SyndicationClient client = new SyndicationClient(); SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri("http://webenliven-space.de/dotnetblog/syndication.axd"));
SampleDataGroup group = new SampleDataGroup("OnlyGroup", "Posts", "Posts", "Assets/DarkGray.png", feed.Subtitle.Text);
foreach (var item in feed.Items) { var images = item.Summary.Text.GetImageSources();
SampleDataItem sampleDataItem = new SampleDataItem(item.Id, item.Title.Text, string.Empty, images.First(), item.Summary.Text, item.Summary.Text, group);
group.Items.Add(sampleDataItem); }
List<SampleDataGroup> groups = new List<SampleDataGroup>(); groups.Add(group);
return groups; } } } |
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks;
namespace DotnetBlogApp.Common { public static class StringContentHelper { public static List<string> GetImageSources(this string htmlContent) { Regex regex = new Regex("<img\\s[^>]*?src=[\"']([^\"']+)[\"'][^>]*>", RegexOptions.IgnoreCase); MatchCollection matches = regex.Matches(htmlContent);
List<string> sources = new List<string>();
foreach (Match item in matches) { sources.Add(item.Groups[1].Value); }
return sources; } } } | Moderiert von Th69: Topic aus WinForms verschoben am So 31.08.2014 um 13:49
|
|
Christian S.
      
Beiträge: 20451
Erhaltene Danke: 2264
Win 10
C# (VS 2019)
|
Verfasst: So 31.08.14 11:38
martinklaus hat folgendes geschrieben : | Ich ha probleme mit dem List.First() methode. |
Und welches?
_________________ Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
|
|
martinklaus 
Hält's aus hier
Beiträge: 5
|
Verfasst: So 31.08.14 12:50
images.First() geht nicht.
Die Methode soll aus dem rss feed das erste Bild suchen und dies wird dan als Kachel Bild genommen
Obwohl beim deugen für mich raus kam das die liste sinnvoll gefühlt wird
|
|
Ralf Jansen
      
Beiträge: 4708
Erhaltene Danke: 991
VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
|
Verfasst: So 31.08.14 13:05
Jetzt noch die Fehlermeldung und wir sind bald soweit das man auch helfen kann.
|
|
martinklaus 
Hält's aus hier
Beiträge: 5
|
Verfasst: So 31.08.14 13:13
invalidoperationexception wurde nicht von benutzercode behandelt.
Zeile 72 var feeds = await blogFeedProxy.LoadFeedsAsync();
hab auch noch das gefunden
- $exception {"Sequence contains no elements"} System.Exception {System.InvalidOperationException}
Moderiert von Th69: C#-Tags hinzugefügt
Zuletzt bearbeitet von martinklaus am So 31.08.14 13:18, insgesamt 1-mal bearbeitet
|
|
Ralf Jansen
      
Beiträge: 4708
Erhaltene Danke: 991
VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
|
Verfasst: So 31.08.14 13:16
Das bekommst du wenn images leer ist.
Falls das ein gültiger Zustand ist benutzt FirstOrDefault anstatt First.
|
|
martinklaus 
Hält's aus hier
Beiträge: 5
|
Verfasst: So 31.08.14 13:20
Ralf Jansen hat folgendes geschrieben : | Das bekommst du wenn images leer ist.
Falls das ein gültiger Zustand ist benutzt FirstOrDefault anstatt First. |
ok nice es kompiliert aber leider sind die Kacheln leer
|
|
martinklaus 
Hält's aus hier
Beiträge: 5
|
Verfasst: So 31.08.14 13:27
Ok das 1 Problem war das 3 Feeds keine Bilder haben und er durch First immer ein Bild wollte für jeden feed
In Moment geht es aber nur mit den 1 Konstruktor nicht mit den 2 wie es soll.
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9:
| public SampleDataItem(String uniqueId, String title, String subtitle, String imagePath, String description, String content) { this.UniqueId = uniqueId; this.Title = title; this.Subtitle = subtitle; this.Description = description; this.ImagePath = imagePath; this.Content = content; } | C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| public SampleDataItem(string p1, string p2, string p3, string p4, string p5, string p6, SampleDataGroup group) { this.p1 = p1; this.p2 = p2; this.p3 = p3; this.p4 = p4; this.p5 = p5; this.p6 = p6; this.group = group; } |
|
|
Th69
      

Beiträge: 4798
Erhaltene Danke: 1059
Win10
C#, C++ (VS 2017/19/22)
|
Verfasst: So 31.08.14 13:59
Hallo und  (da dies bisher keiner vorher getan hat  ),
dein 2. Konstruktor sieht mir doch sehr nach einem vom Visual Studio automatisch generierten aus, zumindestens die erste Zeile davon.
Möchtest du einfach einen weiteren Parameter haben?
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
| public SampleDataItem(String uniqueId, String title, String subtitle, String imagePath, String description, String content, SampleDataGroup group) { this.UniqueId = uniqueId; this.Title = title; this.Subtitle = subtitle; this.Description = description; this.ImagePath = imagePath; this.Content = content; this.Group = group; } |
Du mußt dann aber auch eine Eigenschaft Group dafür anlegen.
PS: Bitte drücke dich demnächst ein bißchen gezielter aus - mein erster Eindruck auf deinen Beitrag war: "Was willst du uns mitteilen?".
|
|