Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > ComboBox > Setting SelectionBoxTemplate has no effect when binding to a collection of UserControls

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

Feed from this thread
  • All Web Leads avatar

    Posted on Oct 13, 2011 (permalink)

    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!

    Reply

  • Answer Yana Yana admin's avatar

    Posted on Oct 18, 2011 (permalink)

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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > ComboBox > Setting SelectionBoxTemplate has no effect when binding to a collection of UserControls
Related resources for "Setting SelectionBoxTemplate has no effect when binding to a collection of UserControls"

WPF ComboBox Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]