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,
I'm sorry but I still don't follow what you are doing. Now you have the Text property bound to the Id of the Items collection - you're not binding to the Id or Name of the data context. Can you post a small sample that shows the problem?
Hmm, ok. Thanks.
It probably doesn't matter now but what I meant by databinding two sources was what I did in my above posts - binding the value to one source and the item list to another source. I think this is what you thought I meant.
Thanks for all your help.
ComboBoxItem and ComboBoxDataItem are two separate things. ComboBoxDataItem is a class that may be used within things like a ComboBoxItemsProvider. When that object is put within a ContentControl such as a ComboBoxItem, the ContentPresenter within it will use the DataTemplate for that type to provide the content. The ComboBoxItem is the item container that the ComboBox itemscontrol will use to host each item. The Style for the ComboBoxItem is what is providing the highlight of the item so if you want to control that highlight in the dropdown then you would want to either put a Style for the ComboBoxItem or set the ItemContainerStyle in a setter for the ComboBoxStyle of the xamComboEditor to a style that does something different for the appearance of the comboboxitem (e.g. provides a different template that changes the appearance of the item when its IsHighlighted is true). If you use something like BamlViewer then you can look at the default styles for the comboboxitem. A basic example would be:
Or if you wanted to set the ComboBoxStyle:
Or since the default MS ComboBoxItem style changes the background to dynamic resources to systemcolor resourcekeys and you didn't mind that the highlight color would be used by the edit portion you could just put resources in comboeditor that use those keys. e.g.
I'm sorry, but here we talk about XamComboEditor and DataTemplate and I seemed the right place. However if I want to change color when it is highlighted, as I do? Can I use another type like ComboBoxItem? Is there a way to take ComboBoxItem automatically?
Thanks for reply
This might be better handled in a separate forum thread but basically that class is not an element so you need to define a DataTemplate whose DataType is igEditors:ComboBoxDataItem.
e.g.
I need to change the style and the template of the ComboBoxDataItem but I can not understand how it makes.Is possible to change the style and the template of the ComboBoxDataItem?