
Ergebnis 1 bis 3 von 3
-
- 03.05.2011, 08:55
- #1
Hallo zusammen
Bin neu hier und auch noch nicht so erfahren mit WP7 Apps.
Hab ein Problem an dem ich schon seit Stunden herum schraube, finde jedoch einfach keine Lösung.
Es ist so; Ich möchte auf Daten in einem XML-File zugreifen(das klappt auch tiptop)
[FONT=Consolas]public[/FONT][FONT=Consolas] class perkitem[/FONT]
[FONT=Consolas] {[/FONT]
[FONT=Consolas] public string name { get; set; }[/FONT]
[FONT=Consolas] public string pro { get; set; }[/FONT]
[FONT=Consolas] public string ang { get; set; }[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] public DownloadStringCompletedEventHandler client_DownloadStrinCompleted { get; set; }[/FONT]
[FONT=Consolas] private void getdata(object sender, RoutedEventArgs e)[/FONT]
[FONT=Consolas] {[/FONT]
[FONT=Consolas] WebClient twitter = new WebClient();[/FONT]
[FONT=Consolas] twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler(xml_DownloadStringComplete);[/FONT]
[FONT=Consolas] twitter.DownloadStringAsync(new Uri("http://localhost/Perk/xml/perk.xml"));[/FONT]
[FONT=Consolas] }[/FONT]
[FONT=Consolas] void xml_DownloadStringComplete(object sender, DownloadStringCompletedEventArgs e)[/FONT]
[FONT=Consolas] {[/FONT]
[FONT=Consolas] XElement xmlperk = XElement.Parse(e.Result);[/FONT]
[FONT=Consolas] listBox1.ItemsSource = from anzeige in xmlperk.Descendants("AKTION")[/FONT]
[FONT=Consolas] select new perkitem[/FONT]
[FONT=Consolas] {[/FONT]
[FONT=Consolas] name = anzeige.Element("NAME").Value,[/FONT]
[FONT=Consolas] pro = anzeige.Element("PRO").Value,[/FONT]
[FONT=Consolas] ang = anzeige.Element("ANG").Value[/FONT]
[FONT=Consolas] };[/FONT]
[FONT=Consolas] }[/FONT]
Diese Daten werden dann in einer ListBox angezeit(auch das klappt tiptop)
[FONT=Consolas]<[/FONT][FONT=Consolas]Grid[/FONT][FONT=Consolas] x[/FONT][FONT=Consolas]:[/FONT][FONT=Consolas]Name[/FONT][FONT=Consolas]="ContentPanel"[/FONT][FONT=Consolas] Grid.Row[/FONT][FONT=Consolas]="1"[/FONT][FONT=Consolas] Margin[/FONT][FONT=Consolas]="12,0,0,90">[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]ListBox[/FONT][FONT=Consolas] Height[/FONT][FONT=Consolas]="508"[/FONT][FONT=Consolas] HorizontalAlignment[/FONT][FONT=Consolas]="Left"[/FONT][FONT=Consolas] Name[/FONT][FONT=Consolas]="listBox1"[/FONT][FONT=Consolas] VerticalAlignment[/FONT][FONT=Consolas]="Top"[/FONT][FONT=Consolas] Width[/FONT][FONT=Consolas]="468"[/FONT][FONT=Consolas] SelectionChanged[/FONT][FONT=Consolas]="listBox1_SelectionChanged">[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]ListBox.ItemTemplate[/FONT][FONT=Consolas]>[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]DataTemplate[/FONT][FONT=Consolas]>[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]StackPanel[/FONT][FONT=Consolas] Orientation[/FONT][FONT=Consolas]="Horizontal"[/FONT][FONT=Consolas] Width[/FONT][FONT=Consolas]="460">[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]TextBlock[/FONT][FONT=Consolas] Text[/FONT][FONT=Consolas]="{[/FONT][FONT=Consolas]Binding[/FONT][FONT=Consolas] name[/FONT][FONT=Consolas]}" />[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]TextBlock[/FONT][FONT=Consolas] Text[/FONT][FONT=Consolas]=" "/>[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]TextBlock[/FONT][FONT=Consolas] Text[/FONT][FONT=Consolas]="{[/FONT][FONT=Consolas]Binding[/FONT][FONT=Consolas] pro[/FONT][FONT=Consolas]}" />[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]TextBlock[/FONT][FONT=Consolas] Text[/FONT][FONT=Consolas]=" "/>[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]TextBlock[/FONT][FONT=Consolas] Text[/FONT][FONT=Consolas]="{[/FONT][FONT=Consolas]Binding[/FONT][FONT=Consolas] ang[/FONT][FONT=Consolas]}" />[/FONT]
[FONT=Consolas]</[/FONT][FONT=Consolas]StackPanel[/FONT][FONT=Consolas]>[/FONT]
[FONT=Consolas]</[/FONT][FONT=Consolas]DataTemplate[/FONT][FONT=Consolas]>[/FONT]
[FONT=Consolas]</[/FONT][FONT=Consolas]ListBox.ItemTemplate[/FONT][FONT=Consolas]>[/FONT]
[FONT=Consolas]</[/FONT][FONT=Consolas]ListBox[/FONT][FONT=Consolas]>[/FONT]
[FONT=Consolas]</[/FONT][FONT=Consolas]Grid[/FONT][FONT=Consolas]>[/FONT]
[FONT=Consolas]<[/FONT][FONT=Consolas]Button[/FONT][FONT=Consolas] Content[/FONT][FONT=Consolas]="Suchmenü"[/FONT][FONT=Consolas] Grid.Row[/FONT][FONT=Consolas]="1"[/FONT][FONT=Consolas] Height[/FONT][FONT=Consolas]="72"[/FONT][FONT=Consolas] HorizontalAlignment[/FONT][FONT=Consolas]="Left"[/FONT][FONT=Consolas] Margin[/FONT][FONT=Consolas]="12,514,0,0"[/FONT][FONT=Consolas] Name[/FONT][FONT=Consolas]="button1"[/FONT][FONT=Consolas] VerticalAlignment[/FONT][FONT=Consolas]="Top"[/FONT][FONT=Consolas] Width[/FONT][FONT=Consolas]="438"[/FONT][FONT=Consolas] Click[/FONT][FONT=Consolas]="button1_Click" />[/FONT]
[FONT=Consolas]</[/FONT][FONT=Consolas]Grid[/FONT][FONT=Consolas]>[/FONT]
Ich möchte jetzt aber diese Daten durch eine Suchfunktion Filtern, dazu habe ich eine weitere Page erstellt mit drei TextBoxen und einem Button.
Kann mir jemand einen Tipp geben wie ich diese TextBox Parameter verwenden soll.
Ich hatte schon einige Ideen die ich jedoch nicht umsetzen konnte:
-Die XML-Daten zwischenspeichern, mit c# if Statements schreiben und nur diese Daten an die ListBox weitergeben die die Suchbedingungen erfüllen.
-Direkt im XAML Code einen Filter setzen. (??)
Bin ich auf dem Holzweg? Bitte um Hilfe.
Gruss
-
Fühle mich heimisch
- 04.05.2011, 11:41
- #2
Hi,
habe mal mit Testdaten gespielt. Folgendes funktioniert zumindest:
Code:List<Colors> color = new List<Colors>{ new Colors { ID = 1, Name="Color1"}, new Colors { ID = 2, Name = "Color2"}, new Colors { ID = 3, Name = "Color3"}, new Colors { ID = 4, Name = "Color4"} }; XElement data = new XElement("colors", from c in color where ((int)c.ID > 1) select new XElement("color", new XElement("id", c.ID), new XElement("name", c.Name))); listBox1.ItemsSource = from anzeige in data.Descendants("color") select new Colors { Name = anzeige.Element("name").Value, ID = Convert.ToInt16(anzeige.Element("id").Value) };
Evtl. hilft dir das ja weiter.
-
- 06.05.2011, 09:47
- #3
Hi loeffel
Zuerst mal danke für Deine Antwort.
Ich habs zwar nicht so wie du gelöst aber du hast mich auf einige Ideen gebracht, dass ist meisstens auch sehr hilfreich
Für die die es interessiert hier meine Lösung, scheint gut zu funktionieren ist aber noch nicht ganz fertig, die if-Bedingung muss natürlich dynamisch sein, halt eine Suchfunktion.
Gruss
Reto
void xml_DownloadStringComplete(object sender, DownloadStringCompletedEventArgs e)
{
List<perkitem> perk = new List<perkitem>();
string name = "";
Int16 pro = 0;
string ang = "";
XDocument perkdoc = XDocument.Parse(e.Result, LoadOptions.None);
foreach (XElement element in perkdoc.Descendants("AKTION"))
{
name = element.Element("NAME").Value;
pro = Convert.ToInt16(element.Element("PRO").Value);
ang = element.Element("ANG").Value;
if (name == "Manor" && pro > 30)
{
perk.Add(new perkitem(name, pro, ang));
}
}
listBox1.ItemsSource = perk;
}
Ähnliche Themen
-
Kontakte Anzeige filtern
Von Mr-Monk im Forum Android AppsAntworten: 1Letzter Beitrag: 09.02.2011, 14:55 -
Eingehende Anrufe bei Roaming filtern
Von SiKa im Forum HTC Touch Pro 2Antworten: 3Letzter Beitrag: 19.12.2009, 21:46 -
Kontaktliste filtern? (will keine google contacts)
Von uga6 im Forum HTC HeroAntworten: 2Letzter Beitrag: 11.09.2009, 15:56 -
htc diamond 2 Outlook Aufgaben filtern
Von Diapete im Forum HTC Touch Diamond 2Antworten: 1Letzter Beitrag: 06.06.2009, 17:45 -
Unterdrückte Anrufe filtern
Von Unregistriert im Forum HTC Touch ProAntworten: 7Letzter Beitrag: 03.05.2009, 22:46
Pixel 10 Serie mit Problemen:...