Only one message can be executed simultaneously in the user interface thread where this code is located. Data binding occurs with a certain priority in individual messages, so you need to make sure that this code:
object test = c.Content;
triggered after these data binding messages are completed. You can do this by queuing up a separate message with the same priority level (or lower) as the data binding:
var c = new ContentControl();
c.SetBinding(ContentControl.ContentProperty, new Binding());
c.DataContext = "Test";
Dispatcher.BeginInvoke((ThreadStart)delegate
{
object test = c.Content;
}, System.Windows.Threading.DispatcherPriority.DataBind);
source
share