Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using System.Windows.Media.Imaging;
- using System.Xml;
- using System.Xml.Linq;
- using System.IO;
- using System.Text;
- namespace Promocje
- {
- public partial class MainPage : UserControl
- {
- public class Produkt
- {
- public string nazwa { get; set; }
- public string cena { get; set; }
- public string obraz { get; set; }
- }
- List<Produkt> lista = new List<Produkt>();
- int pr = 0;
- public MainPage()
- {
- InitializeComponent();
- LoadXMLFile("plik.xml");
- }
- private void LoadXMLFile(string a)
- {
- WebClient xmlClient = new WebClient();
- xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XMLFileLoaded);
- xmlClient.DownloadStringAsync(new Uri(a, UriKind.RelativeOrAbsolute));
- }
- void XMLFileLoaded(object sender, DownloadStringCompletedEventArgs e)
- {
- if (e.Error == null)
- {
- string xmlData = e.Result;
- XmlReader reader = XmlReader.Create(new StringReader(e.Result));
- while (reader.Read())
- {
- if (reader.NodeType == XmlNodeType.Element && reader.Name == "produkt")
- {
- Produkt bogdan = new Produkt();
- reader.ReadToFollowing("nazwa");
- bogdan.nazwa = reader.ReadElementContentAsString();
- reader.ReadToFollowing("cena");
- bogdan.cena = reader.ReadElementContentAsString();
- reader.ReadToFollowing("obraz");
- bogdan.obraz = reader.ReadElementContentAsString();
- lista.Add(bogdan);
- }
- if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "promocje")
- {
- break;
- }
- }
- reader.Close();
- nazwaProduktu.Content = lista.First().nazwa;
- cena.Content = lista.First().cena;
- image1.Source = new BitmapImage(new Uri(lista.First().obraz, UriKind.Relative));
- pr = 0;
- }
- }
- private void Button1_Click(object sender, RoutedEventArgs e)
- {
- if (pr != 0)
- {
- pr = (pr - 1) % lista.Count();
- image1.Source = new BitmapImage(new Uri(lista[pr].obraz, UriKind.Relative));
- cena.Content = lista[pr].cena;
- nazwaProduktu.Content = lista[pr].nazwa;
- }
- else
- {
- pr = lista.Count() - 1;
- image1.Source = new BitmapImage(new Uri(lista[pr].obraz, UriKind.Relative));
- cena.Content = lista[pr].cena;
- nazwaProduktu.Content = lista[pr].nazwa;
- }
- StartAnimation(sender, e);
- }
- private void Button2_Click(object sender, RoutedEventArgs e)
- {
- pr = (pr + 1) % lista.Count();
- image1.Source = new BitmapImage(new Uri(lista[pr].obraz, UriKind.Relative));
- cena.Content = lista[pr].cena;
- nazwaProduktu.Content = lista[pr].nazwa;
- StartAnimation(sender, e);
- }
- private void StartAnimation(object sender, RoutedEventArgs args)
- {
- myStoryboard.Begin();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment