2011-03-18 5 views
12

LinqPad에서 WPF 객체를 정상적으로 인스턴스화 할 수있는 방법이 있습니까? 여기 내 예 (등, 올바른 어셈블리가 쿼리에 추가됩니다)입니다 :LinqPad에서 WPF 예제 만들기

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

w.Show(); 

을하지만,이 끔찍한 죽음을 죽는다 :

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) 

나는이 작업을 얻을 수있는 방법에 대한 단서를?

+9

업데이트 :이 최근 LINQPad 베타에서 해결 - 당신은 당신이 원하는 방식으로 WPF 창을 표시 할 수 있으며,을 끔찍한 죽음은 없습니다. 또한 다음을 수행하면 출력 패널에 WPF 요소가 표시됩니다. PanelManager.DisplayWpfElement (new TextBlock() {Text = "Foo"}); –

답변

6

new Application().Run(w)을 호출하여 메시지 루프를 실행해야합니다.

+0

완벽하게 작동했습니다! 팁 고마워. –

10

다음대로 할 수있는 또 다른 방법 :

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

더 많은 예제 :

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

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