2011-08-24 106 views
0

我是新来的表达混合。在开发桌面应用程序时,我收到一个错误,提示“在声明类型中缺少部分修饰符”,但我已将partial关键字置于public和class之间进行了更正。更正它后,我得到了下面的错误,我会感激你,如果你能好心给妥善解决这些错误声明类型缺少部分修饰符错误

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

请从文件“Window1.xaml.cs”中发布相关代码。在第24行和第67行后面加上邮政编码。 –

+0

private void List_PreviewMouseLeftButtonDown(object sender,MouseButtonEventArgs e){startPoint = e.GetPosition(null);} private void List_MouseMove(object sender,MouseEventArgs e){ Vector diff = startPoint - mousePos; 联系人联系人=(联系人)listView.ItemContainerGenerator.IndexFromContainer(listViewItem); DataObject dragData = new DataObject(“myFormat”,contact); { private void DropList_Drop(object sender,DragEventArgs e){ listView.Items.Add(contact);}}} –

回答

0

要解决第一个错误,请添加此类成员:(只需在任何方法外部将其声明在顶部)

Point st artPoint = Point.Empty;

Point startPoint = new Point(); 

第二个错误是更棘手..从我所看到的,IndexFromContainer方法返回整数,但假设listViewItemContact类型的已经,尝试改变行:

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; 
    } 
} 
+0

第二个错误依然存在。通过将行更改为Point startPoint = Point();将第一个错误更正。 –

+0

请参阅我的编辑以找到可能的解决方案。 –

+0

非常感谢您的答复。我只想编写一个程序,允许用户将存在于一个网格视图中的图像拖放到另一个网格视图。即使我做了上述修改仍然存在错误。 –