I'm working on a custom WPF UserControl and having an issue with one of my DependencyProperties.
So I built a test scenario that looks like this. In the Custom Control..
public static readonly DependencyProperty MyCollectionItemsSourceProperty = DependencyProperty.Register("DynamicHeaderItemsSource", typeof(IEnumerable), typeof(TestUserControl1),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(OnMyCollectionItemsSourceChanged)));
public IEnumerable MyCollectionItemsSource
{
get { return (IEnumerable)GetValue(MyCollectionItemsSourceProperty ); }
set { SetValue(MyCollectionItemsSourceProperty , value); }
}
protected static void OnMyCollectionItemsSourceChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
{
System.Diagnostics.Debug.WriteLine("MyCollection Updated");
}
In my test window's code behind:
public ObservableCollection<string> MyTestStrings { get; set; }
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MyTestStrings.Add("First");
MyTestStrings.Add("Second");
MyTestStrings.Add("Third");
}
And in my test window's XAML:
<Grid>
<local:TestUserControl1 MyCollectionItemsSource="{Binding MyTestStrings}">
</Grid>
The problem is, I never get a notification of any type when the underline collection changes. The OnMyCollectionItemsSourceChanged only ever gets called once: at the beginning when the binding is set. What am I missing?