问题
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()
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
回答1:
You need to call Application.Run
- see here. This will start the event loop for you automatically.
来源:https://stackoverflow.com/questions/20679125/unable-to-enter-text-in-wpf-textbox-in-f-fsi