SetValue makes dependencyProperty null

590 views Asked by At

I am trying to set a value on my dependency property but it always sets 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);
     }
}

When I check the value of value it is actually filled with values and of type IEnumerable<TestEntity>, but for some reason it says null! And when I set everything of type object instead of IEnumerable it works.

1

There are 1 answers

1
kevingoos On BEST ANSWER

I found the problem, because I binded with ObservableCollection, it cannot cast to IEnumerable