This is a migrated thread and some comments may be shown as answers.

Setting SelectionBoxTemplate has no effect when binding to a collection of UserControls

1 Answer 61 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
All Web Leads
Top achievements
Rank 1
All Web Leads asked on 14 Oct 2011, 01:31 AM
Here's my situation (simplified):  I want to bind a collection of user controls to a combo box, but I only want to see the Name of the user controls displayed in the list and displayed as the selected item.

So I have essentially done the following in code: 
var collection = new ObservableCollection<MyUserControl>();
// Add some items to collection here
myRadComboBox.ItemsSource = collection;

And my XAML looks something like the following:
<telerik:RadComboBox SelectionBoxTemplate="{StaticResource MyUserControlDataTemplate}" ItemTemplate="{StaticResource MyUserControlDataTemplate}" />

With the static resource defined as...
<DataTemplate x:Key="MyUserControlDataTemplate" >
    <TextBlock Text="{Binding Name}"/>
</DataTemplate>

And when I run the app, and select an item from the drop down, the visual content of the user control is what shows up in the selection box -- not the name.  It appears that when the data bound to ItemsSource is a collection of UserControls, the specified ItemTemplate will be honored, but not the SelectionBoxTemplate.  I have tried to simplify this as much as possible, but I just cannot get it to work.

Fortunately, when I set the ItemsSource property of my RadComboBox to a collection of some other object which had a "Name" property (without making any other changes to the XAML), I got exactly what I expected to see -- the content of the object's Name property showed up in the selection box.

Please tell me that what I'm seeing is not the expected behavior when binding to a collection of user controls!

1 Answer, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 18 Oct 2011, 04:35 PM
Hello,

It is not supported to use UI elements as items of the RadComboBox. Please replace the UserControls with a custom object in order to fix the problem.

All the best,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ComboBox
Asked by
All Web Leads
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or