Is there any way to sanely instantiate WPF objects in LinqPad? Here's my example (the correct assemblies are added in the query, etc):
var w = new Window();
w.Loaded += (o,e) => {
w.Content = new TextBlock() { Text = "Foo" };
};
w.Show();
However, this dies a horrible death:
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at System.Windows.Input.TextServicesContext.StopTransitoryExtension()
at System.Windows.Input.TextServicesContext.Uninitialize(Boolean appDomainShutdown)
at System.Windows.Input.TextServicesContext.TextServicesContextShutDownListener.OnShutDown(Object target, Object sender, EventArgs e)
at MS.Internal.ShutDownListener.HandleShutDown(Object sender, EventArgs e)
Any clues on how I can get this to work?
Another way to do it is as follows:
w.ShowDialog();
Dispatcher.CurrentDispatcher.InvokeShutdown(); // Cleanly end WPF session.
More examples:
new Window { Content = "Foo" }.ShowDialog();
new Window { Content = new Button { FontSize = 50, Content = "Foo" } }.ShowDialog();
Dispatcher.CurrentDispatcher.InvokeShutdown(); // Cleanly end WPF session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With