"A binding can only be set on a DependencyProperty of a DependencyObject" 尝试绑定此 ValueConverter 时出错

"A binding can only be set on a DependencyProperty of a DependencyObject" error when attempting to bind this ValueConverter

我有这个class:

public class AssetDescriptionLookupConverter : FrameworkElement, IValueConverter
{
    public IEnumerable<T_AssetDescription> LookupList
    {
        get { return (IEnumerable<T_AssetDescription>)GetValue(LookupListProperty); }
        set { SetValue(LookupListProperty, value); }
    }

    public static readonly DependencyProperty LookupListProperty =
        DependencyProperty.Register("Lookup", typeof(IEnumerable<T_AssetDescription>),
        typeof(AssetDescriptionLookupConverter));

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        T_AssetDescription description = 
            LookupList.FirstOrDefault(x => x.AssetDescriptionID.Equals(value));
        if (description == null) return "";
        return description.Item;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return Binding.DoNothing;
    }
}

当我尝试将其作为资源包含在我的 XAML 中时:

<local:AssetDescriptionLookupConverter 
    x:Key="assetDescriptionLookup" 
    LookupList="{Binding AssetDescriptions}" />

我在 LookupList="{Binding AssetDescriptions}" 下看到一条红色波浪线和错误消息

A 'Binding' cannot be set on the 'LookupList' property of type 'AssetDescriptionLookupConverter'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

这是为什么?我该如何解决?

按照微软CEO的吩咐,我们在注册Dependency时需要遵循他定义的命名规范属性。所以问题是你忘了敲几个键,正确的形式是:

public static readonly DependencyProperty LookupListProperty =
    DependencyProperty.Register("LookupList", typeof(IEnumerable<T_AssetDescription>),
    typeof(AssetDescriptionLookupConverter));