I have a list picker propagated by two strings from an XML file, one a name and one a value.
XmlReader xml = XmlReader.Create("file.xml");
XDocument _doc = XDocument.Load(xml);
var stringNames = from query in _doc.Descendants("string")
select new CustomValue
{
StringName = (string)query.Attribute("name"),
StringValue = (string)query.Attribute("value"),
};
Listpicker.ItemsSource = stringNames;
public class CustomValue
{
public string StringName
{
get;
set;
}
public string StringValue
{
get;
set;
}
}
I can read the value OR name by using ((appname.pagename.CustomValue)(this.Listpicker.SelectedItem)).StringValue
But i cannot set the selectedItem, if I used a method similar to the one above it changes the value of the StringValue in the class CustomValue.
Any help very much appreciated!
Thanks :)
You can't set SelectedItem = "something"
as the collection holds instances of CustomValue
not string
. You have to make the seleccted item one of the availabel items.
Let's say you wanted to selected the first item in your collection. There are 2 ways to do this:
Listpicker.SelectedItem = stringNames.First();
or
Listpicker.SelectedIndex = 0;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.