2011-03-18 27 views
12

LinqPad'de WPF nesnelerini düzgün bir şekilde örneklendirmenin bir yolu var mı? İşte benim örnek (vb doğru meclisleri sorguda eklenir) var:LinqPad'de WPF örnekleri oluşturma

var w = new Window(); 
w.Loaded += (o,e) => { 
    w.Content = new TextBlock() { Text = "Foo" }; 
}; 

w.Show(); 

Ancak bu, korkunç bir ölümle ölür:

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) 

Ben bu işe nasıl alabilirim Herhangi ipuçları?

+9

Güncelleme: Bu son LINQPad betalarına düzeltilmiştir - İstediğiniz herhangi bir şekilde WPF pencereleri gösterebilir ve korkunç ölümler yoktur :) Ayrıca, çıkış panelinde bir WPF öğesi görüntüleyen aşağıdakileri de yapabilirsiniz: PanelManager.DisplayWpfElement (new TextBlock() {Text = "Foo"}); –

cevap

6

new Application().Run(w) numaralı telefonu arayarak bir mesaj döngüsü çalıştırmanız gerekir.

+0

Mükemmel çalıştı! Bahşiş için teşekkürler. –

10

şöyle Bunu yapmamızın bir başka yolu:

w.ShowDialog(); 
Dispatcher.CurrentDispatcher.InvokeShutdown(); // Cleanly end WPF session. 

Daha örnekler:

new Window { Content = "Foo" }.ShowDialog(); 
new Window { Content = new Button { FontSize = 50, Content = "Foo" } }.ShowDialog(); 

Dispatcher.CurrentDispatcher.InvokeShutdown(); // Cleanly end WPF session.