none
WPF window hosted in winform application. RRS feed

  • Question

  • Hi to all,
    i' ve a problem with the manage of wpf windows hosted in a winforms application.
    That is, when wpf windows has to be showed by a click of a button on the winform everything it's ok.
    Instead when the winform application received the request to show the wpf window from a Raise of an event the system give me the following error: 

    The calling thread must be STA, because many UI components require this

    What could be the problem?

    Many thanks.
    Genko
    Tuesday, March 13, 2018 12:29 PM

Answers

  • i think yes, because before the comand to show of the wpf form, i've had to verify the IsInvokeRequest comand on different controls and insert delegate function to execute the controls' code.

    OK, so make sure the code that is creating the WPF control is being invoked through a delegate on the main thread.  You might need to show the code in the event handler if you need help with that part.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by _Genko_ Tuesday, March 13, 2018 10:09 PM
    Tuesday, March 13, 2018 4:29 PM
    Moderator

All replies

  • Is the event being raised on a secondary thread?  If you aren't sure, please show the code which raises the event.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, March 13, 2018 1:23 PM
    Moderator
  • i think yes, because before the comand to show of the wpf form, i've had to verify the IsInvokeRequest comand on different controls and insert delegate function to execute the controls' code.
    Tuesday, March 13, 2018 1:55 PM
  • i think yes, because before the comand to show of the wpf form, i've had to verify the IsInvokeRequest comand on different controls and insert delegate function to execute the controls' code.

    OK, so make sure the code that is creating the WPF control is being invoked through a delegate on the main thread.  You might need to show the code in the event handler if you need help with that part.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by _Genko_ Tuesday, March 13, 2018 10:09 PM
    Tuesday, March 13, 2018 4:29 PM
    Moderator
  • Hi Reed,
    i've resolved with your suggestion.

    Many thanks.
    Genko

    Tuesday, March 13, 2018 10:09 PM