I am making a custom control in WPF. I am still learning the ins-and-outs of what a TemplateBinding is (used a lot in custom controls).
One think I am noticing is that I can't seem to use a TemplateBinding inside of a MulitBinding.
When I try this:
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource MyMultiConverter}">
<Binding ElementName="PART_AComboBox" Path="SelectedItem"/>
<TemplateBinding Property="MyListOne"/>
<TemplateBinding Property="MyListTwo"/>
</MultiBinding>
</ComboBox.ItemsSource>
I get this error:
The value "System.Windows.TemplateBindingExpression" is not of type "System.Windows.Data.BindingBase" and cannot be used in this generic collection.
Parameter name: value
Am I missing something? Is there a way to make this work?
This is the workaround I have going, but it is kind of a hack:
<ListBox x:Name="ListOne"
ItemsSource="{TemplateBinding MyListOne}"
Visibility="Collapsed" />
<ListBox x:Name="ListTwo"
ItemsSource="{TemplateBinding MyListTwo}"
Visibility="Collapsed" />
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource DictionaryFilteredToKeysConverter}">
<Binding ElementName="PART_TextTemplateAreasHost" Path="SelectedItem"/>
<Binding ElementName="ListOne" Path="ItemsSource"/>
<Binding ElementName="ListTwo" Path="ItemsSource"/>
</MultiBinding>
</ComboBox.ItemsSource>
I bind the ListBoxes to the dependency property and then in my mulitbinding I do an element bind to the ItemsSource of the list boxes.
As I said above, this feels like a hack and I would like to know if there is a correct way to do a MultiBinding with a TemplateBinding as one of the components.