I want to add a dependency property to UserControl, which may contain a collection of objects UIElement. You can assume that I should get my control out Paneland use a property for this Children, but this is not suitable for my case.
I changed mine UserControlas follows:
public partial class SilverlightControl1 : UserControl {
public static readonly DependencyProperty ControlsProperty
= DependencyProperty.Register(
"Controls",
typeof(UIElementCollection),
typeof(SilverlightControl1),
null
);
public UIElementCollection Controls {
get {
return (UIElementCollection) GetValue(ControlsProperty);
}
set {
SetValue(ControlsProperty, value);
}
}
}
and I use it as follows:
<local:SilverlightControl1>
<local:SilverlightControl1.Controls>
<Button Content="A"/>
<Button Content="B"/>
</local:SilverlightControl1.Controls>
</local:SilverlightControl1>
Unfortunately, I get the following error when starting the application:
Object of type 'System.Windows.Controls.Button' cannot be converted to type
'System.Windows.Controls.UIElementCollection'.
The section Setting the property using collection syntax explicitly states that:
[...] you cannot explicitly specify [UIElementCollection] in XAML, because UIElementCollection is not a constructive class.
, ? UIElementCollection? , ?