2011-08-24 104 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

非常感謝您的答覆。我只想編寫一個程序,允許用戶將存在於一個網格視圖中的圖像拖放到另一個網格視圖。即使我做了上述修改仍然存在錯誤。 –