C# 无法强制转换类型为';System.Windows.DataObject';输入“;产品「;
我厌倦了在DragDrop中将对象转换为Product,Product类型是EntityFrameWork类型请帮助我该怎么做? 我的代码如下所示:C# 无法强制转换类型为';System.Windows.DataObject';输入“;产品「;,c#,entity-framework,casting,C#,Entity Framework,Casting,我厌倦了在DragDrop中将对象转换为Product,Product类型是EntityFrameWork类型请帮助我该怎么做? 我的代码如下所示: void IDroppingTarget.Drop(GAMA.gpf.Utils.DragDrop.IDropInformation dropInfo) { // ... Product t = (Product)dropInfo.Data; // Data is containign the
void IDroppingTarget.Drop(GAMA.gpf.Utils.DragDrop.IDropInformation dropInfo)
{
// ...
Product t = (Product)dropInfo.Data; // Data is containign the product that
// draged from the sourcecollection
// ...
}
}
你不能就这样投。你需要使用新的方法
var dataObject = dropInfo.Data;
if(dataObject.GetDataPresent(typeof(Product)))
{
Product t = (Product)dataObject.GetData(typeof(Product));
}