I am having no luck finding out what I am doing wrong. I made a user control that has a List<string> for a dependency property. When I data bind to that property, nothing is in the list. I used the same data to bind to a ComboBox and it shows the list just fine.
Here is my dependency property:
public List<string> ValueList
{
get { return (List<string>)GetValue(ValueListProperty); }
set { SetValue(ValueListProperty, value); }
}
public static readonly DependencyProperty ValueListProperty =
DependencyProperty.Register("ValueList", typeof(List<string>),
typeof(ValueBox),
new FrameworkPropertyMetadata
{
DefaultValue = new List<string>(),
DefaultUpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged,
});
Here is my data object that I am trying to bind:
private ObservableCollection<string> _valueList1 = new ObservableCollection<string>();
public ObservableCollection<string> ValueList1
{
get
{
return _valueList1;
}
set
{
if (value != _valueList1)
{
_valueList1 = value;
NotifyPropertyChanged("ValueList1");
}
}
}
It gets populated in the code behind with several values, which I noticed does not fire the Set, but it works with the combobox so I assume that is not the problem.
Here is the XAML for the control. The ComboBox works, my control does not see anything in the ValueList property:
<ComboBox Width="120"
ItemsSource="{Binding ValueList1}"
Text="{Binding Label1}"
IsEditable="True"/>
<uc:UserControl Value="Test"
ValueType="OPTION"
ValueList="{Binding ValueList1}"/>
Now if I put the data in the control in the XAML, it works fine:
<uc:UserControl Value="Yes"
ValueType="OPTION">
<uc:UserControl.ValueList>
<System:String>No</System:String>
<System:String>Yes</System:String>
</uc:UserControl.ValueList>
</uc:UserControl>