extend RadComboBox item

3 posts, 1 answers
  1. Roman
    Roman avatar
    4 posts
    Member since:
    Jul 2012

    Posted 23 Dec 2012 Link to this post

    Hi, I need extend RadComboBoxItem to prevent DropDownClose (in some cases).
    I added this class:

    public class CustomComboItem : RadComboBoxItem
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
            var parentComboBox = ItemsControl.ItemsControlFromItemContainer(this) as RadComboBox;
            if (parentComboBox != null)
                var collection = parentComboBox.ItemsSource as ICustomCollection;
                if (collection != null)
                    var item =
                        collection[parentComboBox.ItemContainerGenerator.IndexFromContainer(this)] as ICustomItem;
                    if (item != null && !item.IsSelectable)

    Idea is to trigger base implementation of MouseLeftButtonUp only if necessary.
    But when I try use this class in XAML:
    <Style x:Key="CustomComboBoxItem" TargetType="controls:CustomComboItem"></Style>
    <Style x:Key="ComboBase" TargetType="controls:CustomCombo">
    //other styles
        <Setter Property="ItemContainerStyle" Value="{StaticResource CustomComboBoxItem}"></Setter>       
    //other styles

    I get XamlParseException in RadComboBox PrepareContainerForItemOverride. I don't apply any styles or bindings in CustomComboBoxItem (but I also use DataTemplate), why I get this error? Is it possible to do such things?

    Thanks for help!
  2. Answer
    Vladi avatar
    749 posts

    Posted 28 Dec 2012 Link to this post

    Hello Roman,

    If you want to customize the RadComboBoxItem by creating a class that inherits RadComboBoxItem you will need to create a custom RadComboBox and override its GetContainerForItemOverride() method in which you should return the custom RadComboBoxItem that you have created.

    You will need to do the following steps:
    1. Create a class MyComboBoxItem that inherits RadComboBoxItem.
    2. Override its OnMouseLeftButtonUp() method with your custom logic.
    3. Create a class MyRadComboBox that inherits RadComboBox.
    4. Override its GetContainerForItemOverride() method to return the newly created MyComboBoxItem.

    Hope this is helpful.

    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Roman
    Roman avatar
    4 posts
    Member since:
    Jul 2012

    Posted 08 Jan 2013 Link to this post

    I didn't know about GetContainerForItemOverride.
    Now everything works great!
    Thanks, Vladi for help!
Back to Top