【发布时间】:2015-08-28 07:36:57
【问题描述】:
我试图在我的依赖属性上设置一个值,但它总是设置为 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 时,它就可以工作了。
【问题讨论】:
-
你什么时候检查房产?它可能为空,因为您检查它为时过早。也许您可以在控件完成加载后检查它。
-
控件已加载,当我选中一个框时我更改了值,所以这不是问题。视图模型的初始值也设置正确。只有当我更改控件内部的值时才会出错!
标签: c# wpf dependency-properties