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

2 posts, 1 answers
  1. All Web Leads
    All Web Leads avatar
    4 posts
    Member since:
    Oct 2008

    Posted 13 Oct 2011 Link to this post

    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!
  2. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 18 Oct 2011 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top