【发布时间】:2019-05-02 03:37:05
【问题描述】:
我有这门课:
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}" 下看到一个红色波浪线,并显示错误消息
无法在“AssetDescriptionLookupConverter”类型的“LookupList”属性上设置“绑定”。 “绑定”只能在 DependencyObject 的 DependencyProperty 上设置。
这是为什么?我该如何解决?
【问题讨论】:
-
您正在注册“查找”属性...?应该是“LoopupList”。
-
我知道这很简单。
标签: c# wpf data-binding dependency-properties