2013-12-19 121 views
0

在下面的F#WPF代碼中,當我從F#FSI'顯示'WPF窗口時,我無法在文本框中輸入任何文本。這是與使用Windows窗體事件循環有關嗎?無法在F#中輸入WPF文本框中的文本FSI

let txtBox = new TextBox() 
txtBox.BorderThickness <- Thickness(2.) 
txtBox.Margin <- Thickness(7.) 
txtBox.IsReadOnly <- false 

let wnd = new Window(Title = "Test", Height = 500., Width = 500.) 
wnd.Content <- txtBox 
wnd.Show() 

基於下面的答案被約翰·帕爾默,我已經更新上面用正確版本的代碼。 下面的代碼現在可以在F#FSI中正常工作。

let txtBox = new TextBox() 
txtBox.BorderThickness <- Thickness(2.) 
txtBox.Margin <- Thickness(7.) 
txtBox.IsReadOnly <- false 

let wnd = new Window(Title = "Test", Height = 500., Width = 500.) 
wnd.Content <- txtBox 

(new Application()).Run(wnd) |> ignore 

回答

2

你需要調用Application.Run - 看here。這將自動啓動事件循環。