【问题标题】:missing partial modifier on declaration type Error声明类型错误缺少部分修饰符
【发布时间】:2011-11-02 12:31:50
【问题描述】:

我是表达式混合的新手。在开发桌面应用程序时,我收到一条错误消息“声明类型缺少部分修饰符”,但我已通过在 public 和 class 之间放置 partial 关键字来纠正它。更正后我得到以下错误,如果您能对这些错误提供适当的解决方案,我将不胜感激

当前上下文中不存在名称“startPoint”
C:\Documents and Settings\acer\Desktop\my inter\rrrr\dragDrop(test1)\dragDrop(test1)\Window1.xaml.cs 24 9 dragDrop(test1)
找不到类型或命名空间名称“contact”(您是否缺少 using 指令或程序集引用?)
C:\Documents and Settings\acer\Desktop\my inter\rrrr\dragDrop(test1)\dragDrop(test1)\Window1.xaml.cs 67 32 dragDrop(test1)
找不到类型或命名空间名称“联系人”(您是否缺少 using 指令或程序集引用?)
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);
}

【问题讨论】:

  • 请贴出文件“Window1.xaml.cs”中的相关代码。邮政编码在第 24 和 67 行附近。
  • 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)listView.ItemContainerGenerator.IndexFromContainer(listViewItem); DataObject dragData = new DataObject("myFormat", contact);{ private void DropList_Drop(object sender, DragEventArgs e){ listView.Items.Add(contact);}}}

标签: c# visual-studio-2008 expression-blend


【解决方案1】:

为了解决第一个错误,添加这个类成员:(只需在任何方法之外声明它)

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

【讨论】:

  • 第二个错误依然存在。第一个错误已通过将行更改为 Point startPoint =Point(); 来纠正;
  • 非常感谢您的回答。我只想编写一个程序,允许用户将一个网格视图中的图像拖放到另一个网格视图中。即使我做了上述修改,错误仍然存​​在。
  • 抱歉,我没办法了。听起来您没有正确使用 Expression Blend,请尝试使用一些工作示例并从那里开始。
  • 提供的答案是正确的。非常感谢。是否可以编写一个程序,允许用户在给定图片数量时将图像拖放到适当的位置。例如:在开发电子产品时学习 oop 的学习工具,为了展示“继承”,我设计了一个使用表情混合的活动。一个图片层次结构将提供一些空白。像家谱一样有一些空白。将给出适当的图片。我想写一个程序允许用户将正确的图片拖放到正确的位置。你能给我一个示例演示代码或tute吗。谢谢
  • Ruwani,这最好作为新问题提出。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-28
  • 1970-01-01
  • 1970-01-01
  • 2013-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多