i am a newbie for develop in c# i am studing this example http://msdn.microsoft.com/en-us/library/hh286405%28v=vs.92%29.aspx in this link you can see the my code where i think i have the problem: http://pastebin.com/LYqzuqYb when i run app and click on button1 i have i have a Invalid Cast Error, i use the cast only in
Category = (DB.Elements)listPicker.SelectedItem
but i don't undestand where is the problem best regads Antonio
More information i use this for insert element in listPicker
public Inserimento()
{
InitializeComponent();
List<Elenco> source = new List<Elenco>();
source.Add(new Elenco() { Elemento = "Value1"});
source.Add(new Elenco() { Elemento = "Value2" });
source.Add(new Elenco() { Elemento = "Value3" });
source.Add(new Elenco() { Elemento = "Value4" });
this.listPicker.ItemsSource = source;
}
Elemento is this class, i use this class for insert and store element in listPicker
namespace Example.ViewModel{
public class Elenco
{ public string Elemento
{
get;
set;
}
}}
When the Inserimento
method is executed your listPicker
contains a list of Elenco
objects. Retrieving an item from that listPicker will retrieve one Elenco
object. So this:
Category = (DB.Elements)listPicker.SelectedItem
Should actually be this:
Category = (Elenco)listPicker.SelectedItem
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.