0

I try to open a WPF window containing my WPF user control on LinaPad.

var w = new System.Windows.Window() { Content = myControl };
w.ShowDialog();

This code works only for the first time execution after opening a query tab. If I execute the code again, then it throw InvalidOperationException saying

Cannot use a DependencyObject that belongs to a different thread than its parent Freezable

Is there any difference between the first time execution environment and the later execution environment in LinqPad?

tk.
  • 1,206
  • 1
  • 23
  • 32

1 Answers1

0

I'm guessing you've created myControl on another thread.

The following works without error for me:

var w = new System.Windows.Window() { Content = "foo" };
w.ShowDialog();

Another solution is simply to dump myControl:

myControl.Dump();

LINQPad will then render it in its output window.

Joe Albahari
  • 30,118
  • 7
  • 80
  • 91