I'm creating a custom control which has an ItemsSource
property:
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create("ItemsSource", typeof(IEnumerable<object>), typeof(RadioButtonsGroup), defaultBindingMode: BindingMode.TwoWay);
public IEnumerable<object> ItemsSource
{
get { return (IEnumerable<object>)GetValue(ItemsSourceProperty); }
set
{
SetValue(ItemsSourceProperty, value);
OnItemsAdded(this, new ItemsAddedEventArgs(value));
}
}
I call the OnItemsAdded
method in the property setter, to initialize the control,
it get called only when I set the property like this:
myCustomControl.ItemsSource = vm.MyList;
but doesn't get called when I set it through data-binding:
<Controls:RadioButtonsGroup ItemsSource="{Binding MyList}" x:Name="myCustomControl"/>
so the control doesn't get the list and isn't initialized at all!
I don't want to use the propertyChanged
delegate, because it's static and I need to use instance members in it.