Riya Sehgal

Riya Sehgal

  • NA
  • 616
  • 160.5k

Filter from XML

Jul 8 2011 12:37 AM
Hi All,

I want to create an search button in my windows phone application which search the text which user enter in textbox from XML and shows only the matching result (not all records) as output:

As for normally display the all records from the XML I use this:

using System.Windows.Media.Imaging;
        public MainPage()
        {
            InitializeComponent();
            SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
        } 
  private void listBox1_Loaded(object sender, RoutedEventArgs e)
        {
             var element = XElement.Load("Data.xml");
             var writer =
             from var in element.Descendants("writer")
             orderby var.Attribute("writerName").Value
             select new Authors
             {
                 writerId = Convert.ToInt32(var.Attribute("writerId").Value),
                 writerName = var.Attribute("writerName").Value,
                 writerImage = GetImage(var.Attribute("writerImage").Value),
                 Description = var.Attribute("Description").Value,
                 Source = new Uri(var.Attribute("Source").Value)
              }; 
            listBoxwriter.DataContext = writer;
        } 
        public ImageSource GetImage(string path)
        {
            return new BitmapImage(new Uri(path, UriKind.Relative));
        }




Answers (2)