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:
And my XAML looks something like the following:
With the static resource defined as...
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!
So I have essentially done the following in code:
var collection = new ObservableCollection<MyUserControl>();// Add some items to collection heremyRadComboBox.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!