【问题标题】:No overload for 'My Void' matches delegate 'My Delegate'?'My Void' 没有超载匹配委托 'My Delegate'?
【发布时间】:2013-07-29 14:14:20
【问题描述】:

我有一个带有一个自定义事件的用户控件。如果重要,这在 Windows Phone 应用程序中。用户控件的 C# 中的事件如下所示:

public delegate void TextChangedVoid(string newText)
public event TextChangedVoid TextChanged;

然后我将它添加到我的 Window 的 XAML:

<local:ClientList TextChanged="clist_TextChanged"...

在页面的 C# 中:

private void clist_TextChanged(string newText)
{
    ...
}

看起来不错,但是每次构建项目时都会出现此错误:

No overload for 'clist_TextChanged' matches delegate 'TextChangedVoid'. 

为什么会这样?我应该在我的活动中使用字符串以外的类吗?

【问题讨论】:

  • 其实我第二次构建的解决方案没有更新

标签: c# silverlight events delegates


【解决方案1】:

原来我应该使用字符串以外的类。我创建了一个继承自 EventArgs 的类来保存字符串变量。这解决了问题。它看起来像:

public partial class ClientChangedEventArgs : EventArgs
{
    public ClientChangedEventArgs(string mewText)
    {
        this.NewText = newText;
    }
    public string NewText;
}

在我的用户控制中:

public delegate void TextChangedVoid(ClientChangedEventArgs e)
public event TextChangedVoid TextChanged;

【讨论】:

    猜你喜欢
    • 2020-05-11
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多