SetValue 使 dependencyProperty 为空
SetValue makes dependencyProperty null
我正在尝试为我的依赖项设置一个值 属性 但它总是设置为 null。
[Description("Binded destination list"), Category("Data")]
public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register("DestinationList", typeof(IEnumerable<TestEntity>), typeof(ListBoxEditLookup), new FrameworkPropertyMetadata(IsDestinationListChangedCallback) { BindsTwoWayByDefault = true, DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged});
public IEnumerable<TestEntity> DestinationList
{
get { return GetValue(ItemsProperty) as IEnumerable<TestEntity>; }
set
{
//After this line it becomes null
SetValue(ItemsProperty, value);
}
}
当我检查 value 的值时,它实际上填充了 IEnumerable<TestEntity>
类型的值,但由于某种原因它显示为 null!当我设置所有对象类型而不是 IEnumerable 时,它就起作用了。
我发现了问题,因为我绑定了 ObservableCollection,它无法转换为 IEnumerable
我正在尝试为我的依赖项设置一个值 属性 但它总是设置为 null。
[Description("Binded destination list"), Category("Data")]
public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register("DestinationList", typeof(IEnumerable<TestEntity>), typeof(ListBoxEditLookup), new FrameworkPropertyMetadata(IsDestinationListChangedCallback) { BindsTwoWayByDefault = true, DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged});
public IEnumerable<TestEntity> DestinationList
{
get { return GetValue(ItemsProperty) as IEnumerable<TestEntity>; }
set
{
//After this line it becomes null
SetValue(ItemsProperty, value);
}
}
当我检查 value 的值时,它实际上填充了 IEnumerable<TestEntity>
类型的值,但由于某种原因它显示为 null!当我设置所有对象类型而不是 IEnumerable 时,它就起作用了。
我发现了问题,因为我绑定了 ObservableCollection,它无法转换为 IEnumerable