[英]WP7 Database and Casting error
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我是 c# 开发的新手,我正在研究这个例子http://msdn.microsoft.com/en-us/library/hh286405%28v=vs.92%29.aspx在这个链接中你可以看到我的代码在哪里我想我遇到了问题: http://pastebin.com/LYqzuqYb当我运行应用程序并单击 button1 我有一个无效的转换错误,我只使用转换
Category = (DB.Elements)listPicker.SelectedItem
but i don't undestand where is the problem best regads Antonio但我不明白问题在哪里最好 regads Antonio
More information i use this for insert element in listPicker更多信息我将其用于 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 Elemento 是这个 class,我用这个 class 在 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.当执行
Inserimento
方法时,您的listPicker
包含一个Elenco
对象列表。 Retrieving an item from that listPicker will retrieve one Elenco
object. So this:从该 listPicker 中检索一个项目将检索一个
Elenco
object。所以这个:
Category = (DB.Elements)listPicker.SelectedItem
Should actually be this:其实应该是这样的:
Category = (Elenco)listPicker.SelectedItem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.