Collection DependencyProperty
Posted: 19 Aug 2018, 02:12
What is the intended way to define DependencyProperties that bind to collections? I have a DependencyProperty defined
that I am binding an ObservableCollection<string> called Interactions to like this
but the setter never gets called. I have tried having them be IEnumerable<string>, IEnumerable, IList<string>, string[], ObservableCollection<int>, and it doesn't work no matter what. My other DependencyProperties work but I can't figure out how to make a DependencyProperty of a collection type.
Code: Select all
public static readonly DependencyProperty InteractionsProperty =
DependencyProperty.Register(nameof(Interactions), typeof(ObservableCollection<string>), typeof(InteractionMenu),
new FrameworkPropertyMetadata(new ObservableCollection<string>()));
public ObservableCollection<string> Interactions
{
get { return GetValue(InteractionsProperty) as ObservableCollection<string>; }
set { SetValue(InteractionsProperty, value); }
}
Code: Select all
<InteractionMenu Interactions="{Binding Interactions}"/>