How can I set the DataTemplate on the XamComboEditor when its items are coming from a ComboBoxItemsProvider?
The items in the ComboBoxItemsProvider are objects with various properties. Say it contains ID and Name. How do I get the XamComboBox to display the ID and Name properties as one item? Eg. Instead of displaying names: "smith, brown, black", display IDs and names: "1 smith, 2 brown, 3 black"?
I'm aware that you can set the data template through ComboBoxStyle property but I'm having trouble with the binding.
<igEditors:XamComboEditor Name="cbo" ItemsProvider="{StaticResource cbip}">
<igEditors:XamComboEditor.ComboBoxStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=ID,
RelativeSource={RelativeSource FindAncestor,
AncestorType=igEditors:XamComboEditor}}"/>
<TextBlock Text="{Binding Path=Name,
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</igEditors:XamComboEditor.ComboBoxStyle>
</igEditors:XamComboEditor>
Since you want to show the Id & Name of your object (i.e. the DataContext), you should remove the RelativeSource otherwise you are trying to bind to properties named Id & Name on the XamComboEditor. If you still have an issue please post a small project showing the problem.
Thanks for your quick reply. My problem is actually that the XamComboBox is bound to a different datasource to the ComboBoxItemsProvider, therefore I need some way of binding to the ComboBoxItemsProvider's datacontext. I understand why what I have doesn't work and I have managed to get to the ItemsProvider's Items (see below) but to bind to the current item's properties in the provider is beyond me.
Is this possible?
<TextBlock Text="{Binding Path=ItemsProvider.Items.ID, RelativeSource={RelativeSource FindAncestor,
<TextBlock Text="{Binding Path=ItemsProvider.Items.Name, RelativeSource={RelativeSource FindAncestor,