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

extend RadComboBox item

2 Answers 79 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Roman
Top achievements
Rank 1
Roman asked on 23 Dec 2012, 12:17 PM
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)
                    return;
            }
        }
        base.OnMouseLeftButtonUp(e);
    }
}

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
</Style>

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 Answers, 1 is accepted

Sort by
0
Accepted
Vladi
Telerik team
answered on 28 Dec 2012, 10:07 AM
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.


Greetings,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Roman
Top achievements
Rank 1
answered on 08 Jan 2013, 08:21 AM
I didn't know about GetContainerForItemOverride.
Now everything works great!
Thanks, Vladi for help!
Tags
ComboBox
Asked by
Roman
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Roman
Top achievements
Rank 1
Share this question
or