我是表达混合的新手。在开发桌面应用程序时,我收到一条错误,说“在声明类型上缺少部分修饰符”,但我已经通过在公共和类之间放置partial
关键字来纠正它。在纠正之后我得到了以下错误,如果你能够妥善解决这些错误,我将非常感谢你
The name 'startPoint' does not exist in the current context C:\Documents and Settings\acer\Desktop\my inter\rrrr\dragDrop(test1)\dragDrop(test1)\Window1.xaml.cs 24 9 dragDrop(test1)
The type or namespace name 'contact' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\acer\Desktop\my inter\rrrr\dragDrop(test1)\dragDrop(test1)\Window1.xaml.cs 67 32 dragDrop(test1)
The type or namespace name 'Contact' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\acer\Desktop\my inter\rrrr\dragDrop(test1)\dragDrop(test1)\Window1.xaml.cs 67 13 dragDrop(test1)
代码:
private void List_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
startPoint = e.GetPosition(null);
}
private void List_MouseMove(object sender, MouseEventArgs e)
{
Vector diff = startPoint - mousePos;
Contact contact = (contact)listView.ItemContainerGenerator.IndexFromContainer(listViewItem);
DataObject dragData = new DataObject("myFormat", contact);
}
private void DropList_Drop(object sender, DragEventArgs e)
{
listView.Items.Add(contact);
}
答案 0 :(得分:0)
要解决第一个错误,请添加此类成员:(只在任何方法之外将其声明在顶部)
Point startPoint = Point.Empty;
Point startPoint = new Point();
第二个错误更棘手..从我所见,IndexFromContainer
方法返回整数,但假设listViewItem
已经是Contact
类型,请尝试将该行更改为:
Contact contact = (Contact)listViewItem;
看起来你错过了Contact
类的定义..找不到任何标准,但我想你的意思是这个类?
public class Contact
{
public Contact()
{
}
public string Name
{
get;
set;
}
public string Email
{
get;
set;
}
public string PhoneNumber
{
get;
set;
}
}