简体   繁体   中英

WPF Is it possible to host a control from one thread in another?

I have a WPF app which has main window started in 'default' UI thread. I also have several other windows each has its own UI thread (by calling System.Windows.Threading.Dispatcher.Run() )

However for a specific reason I would like to have these windows as user controls hosted in the main window.

Is it possible (to have a control which was created in one thread to be hosted in a window created in another thread) ?

Pretty sure the answer is no based on one of the arguments for not using DependencyObject as the base of your ViewModels being threading issues.

KenB on the subject

And I quote:

A DependencyObject has thread affinity - it can only be accessed on the thread on which it was created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM