Establezca el texto de ComboBox haciendo clic en ComboBoxItem

I have a CustomComboBoxItem which is derived from ComboBoxItem

public class CustomComboBoxItem : ComboBoxItem {

    ...

    protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
    {
        base.OnMouseLeftButtonUp(e);
    }

}

I need to set the text of the ComboBox by cliking on the CustomComboBoxItem. I don't want to use the SelectionChanged event on the ComboBox itself because I want it to be set by mouse click.

I really don't have any idea what I should do about it. Please share your ideas with me. thanks a million.

Editar

I have a CustomComboBox which has a TextBox in the ControlTemplate. and in the GetContainerForItemOverride overriden method:

protected override DependencyObject GetContainerForItemOverride()
{
    return new CustomComboBoxItem();
}

preguntado el 28 de mayo de 14 a las 11:05

sorry it is all in code-behind. -

can you try to find Parent? I'll do a test later to see if it possible... -

Oh that sounds a goon idea. I've found an article about it. stackoverflow.com/questions/2399967/… I'm going to test it. -

Why don't you just use the default ComboBox functionality??? There's a TextBox en el defecto ControlTemplate and it is automatically set to the selected item too. -

¿Resolviste tu problema? -

1 Respuestas

Finally I solved the problem with this line of code in CustomComboBoxItem

var parent = ItemsControl.ItemsControlFromItemContainer(this) as CustomComboBox;

contestado el 28 de mayo de 14 a las 18:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.