WPF Drag & Drop of integer into datagrid of object
I have a datagrid in a window of my WPF MVVM Applicatiion, in another window I have a datagrid of another type of object.
As long as the two objects in the different datagrids matches, then there is no problem. But in this occasion I have two different objects in these windows.
What I want to do in my target window is that in my code behind cha开发者_运维问答nge the object in the DragEvent to the object that matches the recieving grids object, something like this:
void dgdIngredient_PreviewDrop(object sender, DragEventArgs e)
{
if ((e.Data.GetData("**MyTypeOfObject**",true) as VMProductComponent) != null)
{
VMProductComponent vmp = new VMProductComponent();
e.Data.SetData((e.Data.GetData(typeof(object)) as FOODit.Matilda.ViewModel.VMProductComponent));
}
}
However, the conversion always fail, and I allways get null in my GetData() statement, can anyone help me get this right, if it is even possible.
Thank you in advance.
/Peter
Seems as though I had been working for too long, I was trying to convert my source object to my target object directly, so this is the correct solution.
private void target_Drop(object sender, DragEventArgs e)
{
MyTargetType data = e.Data.GetData(typeof(MyTargetType)) as MyTargetType;
if (data != null)
{
target.Content = data;
}
}
/Peter
精彩评论