For some controls, such as ComboBox, the following are valid ways to add items into the Items collection instead of using the ItemsSource property:
<ComboBox><ComboBoxItem Content="Item1" /><ComboBoxItem Content="{x:Bind Item2Text, Mode=OneWay}" /></ComboBox><!-- OR --><ComboBox><ComboBox.Items><ComboBoxItem Content="Item1" /><ComboBoxItem Content="{x:Bind Item2Text, Mode=OneWay}" /></ComboBox.Items></ComboBox><!-- OR --><ComboBox><x:String>Item1</x:String><!-- Is it possible to somehow use x:Bind or Binding in these x:String elements? --><x:String>Item2</x:String></ComboBox>
The following lines in the documentation for the ComboBoxItem
Class seem to imply that in all three of these examples, (even the one using x:String elements) the items are being automatically wrapped inside ComboBoxItems:
The ComboBoxItem class provides the container for items displayed in aComboBox control. You populate the ComboBox by adding objects directlyto its Items collection or by binding its ItemsSource property to adata source. When items are added to the ComboBox, a ComboBoxItemcontainer is created automatically for each item in the collection.
You can specify the look of the ComboBoxltem by setting the ComboBox'sItemContainerStyle property to a Style with a TargetType ofComboBoxItem.
How would I make a custom control that behaves in a similar way? i.e. CustomControl which automatically wraps data added to it's Items collection inside CustomControlItem containers.
I've been able to do something close by adding an ObservableCollection<string> Items DependencyProperty
to my custom control. This isn't quite what I want though, since it only works with x:String elements, which I can't x:Bind the value of (afaik).