2

I am quite new to the WPF....I ran into this issue where it says "The dropdownclosed is not a routedevent". here is my code:

<DataGridComboBoxColumn x:Name="Fleet_Combo" Header="Fleet" Width = "30*" ItemsSource="{Binding acTypeFleet}" SelectedItemBinding="{Binding Fleet,Mode=TwoWay}">
                    <DataGridComboBoxColumn.EditingElementStyle>
                        <Style TargetType="ComboBox">
                            <EventSetter Event="SelectionChanged" Handler="FleetComboBox_SelectionChanged"/>
                            <EventSetter Event="DropDownClosed" Handler="ComboBox_DropDownClosed"/>
                        </Style>
                    </DataGridComboBoxColumn.EditingElementStyle>                        
                </DataGridComboBoxColumn>

Please help, thank you.

Heisenberg
  • 764
  • 6
  • 20
  • related: [How to get a combobox to appropriately set focus directly after the popup closes](https://stackoverflow.com/questions/9710013/how-to-get-a-combobox-to-appropriately-set-focus-directly-after-the-popup-closes) – mcalex Oct 09 '17 at 19:02
  • thank you. if you post it I can mark it as answer. – Heisenberg Oct 09 '17 at 21:03

1 Answers1

1

As the error message says: DropDownClosed isn't a RoutedEvent, so you can't create a style for ComboBoxes and have them all inherit the event via an EventSetter.

A workaround to invoke the event is to use an event that is a RoutedEvent, and hook into that appropriately. A suitable candidate is Loaded. Follow Alain's answer here to get the Loaded event:

<Style x:Key="ComboBoxCellStyle" TargetType="ComboBox">
  <EventSetter Event="Loaded" Handler="ComboBox_Loaded" />
</Style>

From the loaded event, you can get to the DropDownClosed event

private void ComboBox_Loaded(object sender, RoutedEventArgs e)
{
  ((ComboBox)sender).DropDownClosed -= ComboBox_OnDropDownClosed;
  ((ComboBox)sender).DropDownClosed += new 
     System.EventHandler(ComboBox_OnDropDownClosed);
}

and from there call the appropriate handler:

void ComboBox_OnDropDownClosed(object sender, System.EventArgs e)
{
  ...
}
mcalex
  • 6,628
  • 5
  • 50
  • 80