views:

35

answers:

2

When the list is dropped down an the mouse hovers over an item in the drop-down list, the item becomes highlighted but the selected value shown in the text box does not change unless the item is clicked. I am looking for a way to modify the mouse over behavior in a control that inherits from ComboBox. I tried overriding function like OnMouseEnter & OnMouseMove etc.

A: 

Instead create your own control using a TextBlock, a ToggleButton with an arrow and a ListBox. Show the Listbox when the ToggleButton is checked. When user do mouse over a listboxitem, change the text in the Textbox and update some property for selected item or fire an event.

Wallstreet Programmer
A: 

You can do it by overriding OnMouseMove. The OriginalSource property of the MouseEventArgs will give you the element directly under the mouse. You can use ContainerFromElement to get the ComboBoxItem that contains that element and then ItemContainerGenerator.ItemFromContainer to get the item to select:

protected override void OnMouseMove(MouseEventArgs e)
{
    base.OnMouseMove(e);
    var container = ContainerFromElement((DependencyObject)e.OriginalSource);
    if (container != null)
    {
        SelectedItem = ItemContainerGenerator.ItemFromContainer(container);
    }
}
Quartermeister