Unable to enter text in WPF TextBox in F# FSI

巧了我就是萌 提交于 2019-12-12 15:51:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!