How to Set EmptySelectionBoxTemplate in code?

3 posts, 1 answers
  1. Bob
    Bob avatar
    63 posts
    Member since:
    Aug 2010

    Posted 08 Aug 2011 Link to this post

    I have a RadRibbonComboBox in a RadRibbonTab in a RadRibbonBar.  Looks something like this:

        <telerik:RadRibbonTab Header="Tab 2" x:Name="Tab2">
            <telerik:RadRibbonGroup Header="Select an item">
                <StackPanel Orientation="Vertical" Margin="0,5,0,0">
                    <telerik:RadRibbonComboBox Name="myComboBox" Margin="0,5,0,0" >
                        <telerik:RadRibbonComboBoxItem Content="New Item..." Selected="NewItem_Selected"></telerik:RadRibbonComboBoxItem>

    I have defined three different Data Templates in the resources like this:

        <DataTemplate x:Key="EmptyTemplate1">
            <TextBlock FontStyle="Italic" Text="Select a value from the list" />
        <DataTemplate x:Key="EmptyTemplate2">
            <TextBlock FontStyle="Italic" Text="There are no selections at this time" />
        <DataTemplate x:Key="EmptyTemplate3">
            <TextBlock FontStyle="Italic" Text="Please complete the first tab before selecting" />

    I want to use a specific Data Template for the EmptySelectionBoxTemplate depending on various conditions.  Therefore, I want to set the EmptySelectionBoxTemplate in code.  I have tried setting the template like this:

    myComboBox.EmptySelectionBoxTemplate = (DataTemplate)FindResource("EmptyTemplate1");

    The resource is found, and appears to be set in the combo box, but the display does not get altered.  I also tried invalidating the property and visual state:


    Invalidating did not help.  The combo box selection is -1, and if I set the EmptySelectionBoxTemplate in XAML, the box displays the message correctly.

    What is the correct way to change this template in code?
  2. Answer
    Yana avatar
    4604 posts

    Posted 09 Aug 2011 Link to this post

    Hello Bob,

    You should reset the ComboBox template, please try it like this:

    private void Button_Click(object sender, RoutedEventArgs e)
        comboBox1.SelectedIndex = -1;
        comboBox1.EmptySelectionBoxTemplate = (DataTemplate)FindResource("EmptyTemplate1");
    private void ResetTemplate()
        var temp = comboBox1.Template;
        comboBox1.Template = null;
        comboBox1.Template = temp;

    and let us know the result.

    Kind regards,
    the Telerik team

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

  3. Bob
    Bob avatar
    63 posts
    Member since:
    Aug 2010

    Posted 09 Aug 2011 Link to this post

    Thank you, the reset code worked.
Back to Top