Korzystanie DependencyProperty ItemsSource w CustomControl a następnie wiążą się z tym DependencyProperty
to XAML-Code (Rozpoznaj DataContext ListBox):
<UserControl
x:Name="MyControl">
<ListBox
DataContext="{Binding ElementName=MyControl}"
ItemsSource="{Binding ItemsSource}">
</ListBox>
</UserControl>
to kodzie:
public partial class MyCustomControl
{
public IEnumerable ItemsSource
{
get { return (IEnumerable)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(IEnumerable),
typeof(ToolboxElementView), new PropertyMetadata(null));
}
Jest to kod, gdzie można korzystać z "MyCustomControl":
<Window>
<local:MyCustomControl
ItemsSource="{Binding MyItemsIWantToBind}">
</local:MyCustomControl>
</Window>
'newValueINotifyCollectionChanged' jest zawsze' null'. –
Po wyczyszczeniu listy ograniczonej wartość OnItemsSourcePropertyChanged nie zostanie wywołana ... Czy powinien nią być? – user3260977