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));
}
Riya SehgalPosted Jul 8, 2011, 2:12 AM
Could you provide any tutorial link, I have that theoretical idea but not able to implement properly...
Amit ChoudharyPosted Jul 8, 2011, 2:01 AM
Well in search button event you might want to filter the listBoxWriter.DataContext. create linq query to match the text with all the properties of each object like writerName, Description etc. and bind the list again with the search result.
Thanks.