This is a migrated thread and some comments may be shown as answers.

RadComboBoxItem Style problem

3 Answers 149 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Son
Top achievements
Rank 1
Son asked on 03 Oct 2011, 11:35 AM
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

3 Answers, 1 is accepted

Sort by
0
Dani
Telerik team
answered on 04 Oct 2011, 10:46 AM
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 >>
0
Son
Top achievements
Rank 1
answered on 04 Oct 2011, 10:51 AM
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
0
Accepted
Dani
Telerik team
answered on 04 Oct 2011, 11:24 AM
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 >>
Tags
ComboBox
Asked by
Son
Top achievements
Rank 1
Answers by
Dani
Telerik team
Son
Top achievements
Rank 1
Share this question
or