【问题标题】:Error XLS0525 Method not found in type - when binding a generic delegate?错误 XLS0525 在类型中找不到方法 - 绑定泛型委托时?
【发布时间】:2020-07-20 14:25:24
【问题描述】:

我将自定义控件的属性绑定到Func<object, bool>。这在运行时正常工作,但设计师抱怨......

详细信息 - 我的视图模型中有以下属性:

class Smth
{
    public Func<object, bool> TestToPerform
    {
        get
        {
            return TestToPerformFunc;
        }
    }

    protected abstract bool TestToPerformFunc(object item);
}

然后在 XAML 中:

<local:ControlA
        TestToPerform="{Binding Foo.Bar.TestToPerform}" />

在设计器中,文本“TestToPerform”带有蓝色下划线,并显示以下错误:

Error   XLS0525 Method 'TestToPerform' not found in type 'Smth'

错误当然是不正确的。

我试图解决它:

using FuncObjectBool = Func<object, bool>;
...

    public FuncObjectBool TestToPerform
    {
        get
        {
            return TestToPerformFunc;
        }
    }

但它没有任何好处。

我正在使用 VS2019 16.6.2。

【问题讨论】:

    标签: c# wpf xaml generics delegates


    【解决方案1】:

    这原来是一个设计错误。即使不使用泛型,显然也会发生。此处已报道:

    https://developercommunity.visualstudio.com/content/problem/997181/xls0525-error-when-attempting-to-bind-delegate-in.html

    尝试在 WPF 设计器中绑定委托时出现 XLS0525 错误 - Kevin Bost 于 4 月 19 日下午 7:42 报道

    此示例项目here 重现问题。

    控件,DialogHost 公开一个委托 (DialogClosingEventHandler) 依赖属性。我试图在我的 视图模型到这个属性。该应用程序编译并运行成功, 我的视图模型中的委托被调用。然而在 设计师我收到 XLS0525 错误。 ...

    后续评论指出:

    6 月 3 日上午 06:43 对此问题的修复现已推出预览版 释放。

    当前状态:

    已修复 - 待发布已修复:visual studio 2019 版本 16.7 预览版 2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多