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

How to inherit RadComboBox ?

4 Answers 197 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Olivier
Top achievements
Rank 1
Olivier asked on 12 Mar 2015, 04:07 PM
Hello
I would create my own RadComboBox (for adding features) and add a button at right (see capture)
I create a control inherit of RadComboBox :
public class MyComboBox : Telerik.Windows.Controls.RadComboBox
{
 
}
And associate style :
<Style x:Key="MyComboBoxStyle" TargetType="Controls:MyComboBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Controls:MyComboBox" >
                    <Grid x:Name="LayoutRoot">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
 
                        <telerik:RadComboBox x:Name="PART_RadComboBox" Grid.Column="0"
                                             ItemsSource="{TemplateBinding ItemsSource}"
                                             SelectedItem="{TemplateBinding SelectedItem}"
                                             SelectedValue="{TemplateBinding SelectedValue}"
                                             DisplayMemberPath="{TemplateBinding DisplayMemberPath}"
                                             SelectedValuePath="{TemplateBinding SelectedValuePath}">
                        </telerik:RadComboBox>
 
                        <telerik:RadButton x:Name="PART_RadButton" Grid.Column="1" Content="+"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
But MyComboBoxStyle is never use, I think RadComboBox always override my style because if I inherit System.Windows.ComboBox it's work.
Can you help me ? Or I must create UserControl and rewrite all DependencyProperty of RadComboBox ? 
Thanks in advance

PS : I use Telerik 2014 Q2.

4 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 16 Mar 2015, 09:40 AM
Hello Arnaud,

You could either inherit from RadComboBox, add the needed properties and extract and modify the default Style and Template of the control in order to add the button. Afterwards you would need to apply the Style with TargetType the new control.

Or you can simply create new UserControl, add RadComboBox and the Button as content. In the code behind you can implement the needed functionality without applying any Styles and Templates.

Hope this helps.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Olivier
Top achievements
Rank 1
answered on 18 Mar 2015, 01:27 PM
I would inherit RadComboBox but without extract Style and Template, only use a Style BasedOn RadComboBoxStyle
I try with System.Controls.ComboBox and it's work but not with RadComboBox. 
MyComboBox.cs (very simple)
public class MyComboBox : Telerik.Windows.Controls.RadComboBox
{
}
 
public class MyComboBox2 : System.Windows.Controls.ComboBox
{
}
MyComboBox.xaml
<Style x:Key="MyComboBoxStyle" TargetType="Controls:MyComboBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Controls:MyComboBox" >
                    <Grid x:Name="LayoutRoot">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
 
                        <telerik:RadComboBox x:Name="PART_RadComboBox" Grid.Column="0"
                                             ItemsSource="{TemplateBinding ItemsSource}"
                                             SelectedItem="{TemplateBinding SelectedItem}"
                                             SelectedValue="{TemplateBinding SelectedValue}"
                                             DisplayMemberPath="{TemplateBinding DisplayMemberPath}"
                                             SelectedValuePath="{TemplateBinding SelectedValuePath}">
                        </telerik:RadComboBox>
 
                        <telerik:RadButton x:Name="PART_RadButton" Grid.Column="1" Content="+"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
 
    <Style x:Key="MyComboBoxStyle2" TargetType="Controls:MyComboBox2">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Controls:MyComboBox2" >
                    <Grid x:Name="LayoutRoot">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
 
                        <ComboBox x:Name="PART_RadComboBox" Grid.Column="0"
                                             ItemsSource="{TemplateBinding ItemsSource}"
                                             SelectedItem="{TemplateBinding SelectedItem}"
                                             SelectedValue="{TemplateBinding SelectedValue}"
                                             DisplayMemberPath="{TemplateBinding DisplayMemberPath}"
                                             SelectedValuePath="{TemplateBinding SelectedValuePath}">
                        </ComboBox>
 
                        <telerik:RadButton x:Name="PART_RadButton" Grid.Column="1" Content="+"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
And my View
<Label Grid.Row="0" Content="Telerik.Windows.Controls.RadComboBox"/>
        <Control:MyComboBox Grid.Row="1" Margin="5" Style="{StaticResource MyComboBoxStyle}"
                             ItemsSource="{Binding ListItems, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
                             DisplayMemberPath="Item2" SelectedValuePath="Item1"
                             SelectedValue="{Binding Entite.IdSubItem, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
 
        <Label Grid.Row="2" Content="System.Windows.Controls.ComboBox"/>
        <Control:MyComboBox2 Grid.Row="3" Margin="5" Style="{StaticResource MyComboBoxStyle2}"
                             ItemsSource="{Binding ListItems, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
                             DisplayMemberPath="Item2" SelectedValuePath="Item1"
                             SelectedValue="{Binding Entite.IdSubItem, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
As you can see in my screenshot, with ComboBox, my button appear but not with RadComboBox, why ??
Thanks in advance for help
0
Accepted
Kalin
Telerik team
answered on 20 Mar 2015, 04:22 PM
Hi Arnaud,

RadComboBox uses the NonEditableTemplate and EditableTemplate properties. So if you change the Setter to NonEditableTemplate - it will appear the same way as the regular ComboBox:

<Style x:Key="MyComboBoxStyle" TargetType="Controls:MyComboBox">
<Setter Property="NonEditableTemplate">

Hope this helps.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Olivier
Top achievements
Rank 1
answered on 23 Mar 2015, 08:32 AM
Thanks very much
I don't remember RadComboBox doesn't have one Template but two templates.
That's work great. 
Regards
Tags
ComboBox
Asked by
Olivier
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Olivier
Top achievements
Rank 1
Share this question
or