As for question, I've created a custom UserControl. It has an ItemsControl which ItemsSource is binded to a property bindable as DependecyProperty.
MyControl XAML:
<Grid>
<ItemsControl ItemsSource="{Binding Path=InternalControl}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
MyControl Code:
public static readonly DependencyProperty SetInternalControlProperty =
DependencyProperty.Register(
nameof(ObservableCollection<dynamic>),
typeof(ObservableCollection<dynamic>),
typeof(UtilityExpander));
public ObservableCollection<dynamic> InternalControl
{
get { return (ObservableCollection<dynamic>)GetValue(SetInternalControlProperty); }
set { SetValue(SetInternalControlProperty, value); }
}
Main XAML:
<Controls:UtilityExpander InternalControl="{Binding GasControl}"/>
Main Code:
private ObservableCollection<UtilityGas> _gasControl;
public ObservableCollection<UtilityGas> GasControl { get => _gasControl; set { _gasControl = value; NotifyPropertyChanged(); } }
When running on the InitializeComponent() I get
System.Windows.Markup.XamlParseException: 'A 'Binding' cannot be set on the 'InternalControl' property of type 'UtilityExpander'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.'
The reason why I'm using dynamic is that I want to use the control with different type of IEnumerable<objects>