I put reading barcode in separate method which reads the barcode and put it in a textbox named barcode. and created a button that will load data coresponding to that barcode , but facing problem
private void Load_Click(object sender, RoutedEventArgs e)
{
var str = @"<Books xmlns=""""> <book Barcode=""780672318863""><Serial>11</Serial>
<name>abc</name> <detail>Fantasy</detail></book>
<book Barcode=""780672318864""><Serial>12</Serial>
<name>abc</name><detail>Fantasy1</detail></book></Books>";
var strBarcode = barcode.Text;
MessageBox.Show(strBarCode);
XDocument docX = XDocument.Parse(str);
var s = docX.Descendants("book").FirstOrDefault(a => a.Attribute("Barcode").Value == strBarcode);
spnl.DataContext = s;
}
now Messagebox says strBarCode has correct value but it is not showing up in program and
s value is coming out to be null
on other hand if i put directly “780672318863” in place of strBarcode it is showing value correctly
can anyone tell me where i am going wrong ?
Not reproducable.
I ran your code with
docX.Descendants("book")...and it produces the correct element.You could try
but for the rest you will just have to look around in the debugger.