无法在F#FSI的WPF文本框中输入文本

问题描述:

在下面的F#WPF代码中,当我从F#FSI显示" WPF窗口时,无法在文本框中输入任何文本.这与正在使用Windows窗体事件循环有关吗?

In the F# WPF code below, I am unable to enter any text in the text box when I 'show' the WPF window from the F# FSI. Is this something to do with Windows Forms Event loop being used?

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()

根据 John Palmer 的以下回答,我已使用正确的版本更新了上面的代码. 下面的代码现在可以在F#FSI中正常工作.

Based on the answer below by John Palmer, I have updated the code above with the correct version. The code below now works correctly in 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

您需要致电Application.Run-请参见

You need to call Application.Run - see here. This will start the event loop for you automatically.