I have been searching for an answer for 24 hours, but I did not find it. I am new to C#. I have found a tutorial, from where I have used this code:
XDocument loadedCustomData = XDocument.Load("PeopleCustom.xml");
var filteredData = from c in loadedCustomData.Descendants("Person")
where c.Attribute("Age").Value == current.ToString()
select new Person
{
FirstName = (string)c.Attribute("FirstName").Value,
};
listBox1.ItemsSource = filteredData;
public class Person
{
string firstname;
string lastname;
int age;
public string FirstName
{
get { return firstname; }
set { firstname = value; }
}
public string LastName
{
get { return lastname; }
set { lastname = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
}
XML is like this:
<People>
<Person
FirstName="Kate"
LastName="Smith"
Age="1" />
<Person
...
/>
</People>
It works, but it puts all output into listbox. I want strings. I tried to get string from list box (like this listBox1.Items[0].ToString();), but all I get is something like this: ProjectName.MainPage+Person. I also tried to get it from filteredData, but no success. Is there any way to get data from XML to strings? Thank you in advance for your answer