RadComboBoxItem Style problem

4 posts, 1 answers
  1. Son
    Son avatar
    22 posts
    Member since:
    Jun 2011

    Posted 03 Oct 2011 Link to this post

    I have a problem with set style for RadComboBoxItem. How can I apply a style with fontsize, font family, foreground, so on .. ?
    <telerik:RadComboBox Margin="2" x:Name="DistanceComboBox" VerticalAlignment="Center" Width="50" SelectedIndex="0">
        <telerik:RadComboBox.Items>
            <telerik:RadComboBoxItem>5</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>10</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>20</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>30</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>50</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>75</telerik:RadComboBoxItem>
        </telerik:RadComboBox.Items>
    </telerik:RadComboBox>

    I tried with 
    <telerik:RadComboBoxItem Style="{StaticResource MyStyle}">5</telerik:RadComboBoxItem>
    It just applies for ItemContainer but not for SelectedItem
    Please help me
    Thanks
  2. Dani
    Admin
    Dani avatar
    848 posts

    Posted 04 Oct 2011 Link to this post

    Hello Son,

    You can apply the formatting properties to the selected RadComboBoxItem via the SelectionBoxTemplate property.

    Please, consider the following example:

    <UserControl.Resources>
          <Style TargetType="telerik:RadComboBoxItem" x:Key="ItemContainerStyle">
                <Setter Property="Foreground" Value="Lime" />
                <Setter Property="FontWeight" Value="Bold" />
            </Style>
      
            <DataTemplate x:Key="SelectionComboBoxTemplate">
                <Grid>
                    <TextBlock Text="{Binding Name}" Foreground="Lime" FontWeight="Bold" />
                </Grid>
            </DataTemplate>
        </UserControl.Resources>
      
    <Grid>
     <telerik:RadComboBox x:Name="RadComboBox3" Grid.Row="1" Grid.Column="1" ItemContainerStyle="{StaticResource ItemContainerStyle}" SelectionBoxTemplate="{StaticResource SelectionComboBoxTemplate}"
                        ItemsSource="{Binding Agency}" SelectedIndex="0" VerticalAlignment="Center"
                        DisplayMemberPath="Name" Margin="0 0 20 0" />
    </Grid>


    I hope this will be helpful. If you need further help on this issue, please let me know.

    All the best,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. Son
    Son avatar
    22 posts
    Member since:
    Jun 2011

    Posted 04 Oct 2011 Link to this post

    Hi Dani
    I am not using ItemSource property. I set hardcode with RadComboboxItem
    <telerik:RadComboBox.Items>
            <telerik:RadComboBoxItem>5</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>10</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>20</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>30</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>50</telerik:RadComboBoxItem>
            <telerik:RadComboBoxItem>75</telerik:RadComboBoxItem>
        </telerik:RadComboBox.Items>

    So ItemContainerStyle, SelectionBoxTemplate are not effect in this case
    Can You please check it again ?
    Thanks
  5. Answer
    Dani
    Admin
    Dani avatar
    848 posts

    Posted 04 Oct 2011 Link to this post

    Hello Son,

    The ItemContainerStyle and the SelectionBoxTemplate will work only when you data bind the RadComboBox items. Please, use a data bound collection of RadComboBoxItems if possible.

    Greetings,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top