0

I have a wpf UserControl that handles events from a ComboBox. The control subscribes to the ComboBoxes' DropdownClosed event. I'm facing the problem, that the Combobx base implementation peforms unpleasant default code, after running through the handler.

I like to know if there's a way to simply place my code, "synchronous" after the handler finished.

I found out a common way is using BeginInvoke:

void OnComboBoxDropDownClosed()
{
    ...
    Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => MyCodeAfterHandlerFinished()));
}

I don't think i need this (because msdn tells me it runs asynchronously), What is best practice ?

more explained: 1) get notified when DropDownClosed() is fired by the ComboBox base (This event can be seen as the condition for "MyCode()") 2) wait until the ComboBox base implementation has run through all its invocation list and has dispatched all its event subscribers. 3) run MyCode() --> how place MyCode using Invoke / BeginInvoke ?

deafjeff
  • 754
  • 7
  • 25
  • `Dispatcher.Invoke` calls delegate synchronously. But right now your question is not clear what you are trying to achieve. Can you add more details with some code in your question? – Rohit Vats Apr 14 '14 at 11:32
  • Sure: 1st) I want to get notified when the "DropDownClosed" event occurs. This is the condition to run "MyFunction()" 2nd) "MyFunction()" should be called / invoked, when the ComboBox base finfished its code that called the ComboboxDropdown event. (the base class implementation) – deafjeff Apr 14 '14 at 11:36
  • So simply hook event `DropDownClosed` event of ComboBox and do your stuff over there. ``. Don't worry about ComboBox default code because it is already well handled by microsoft guys. – Rohit Vats Apr 14 '14 at 11:41
  • @deafjeff Do you mean that your ComboBox you are hooked to is actualy another class that inherits from ComboBox and handles this event too? – Dmitry Apr 14 '14 at 11:54
  • no - it's much simpler, I just edited my question (see above) – deafjeff Apr 14 '14 at 11:58
  • ok I see but what is wrong with base implementation? – Dmitry Apr 14 '14 at 12:09
  • nothing is wrong. I want to change behavior by attaching some custom code. I don't like the thought of deriving my own ComboBox control for only this reason. So I thought of Invoking() – deafjeff Apr 14 '14 at 12:30

0 Answers0