Bikal Lem
Bikal Lem

Reputation: 2423

Unable to enter text in WPF TextBox in F# FSI

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

Upvotes: 3

Views: 304

Answers (1)

John Palmer
John Palmer

Reputation: 25516

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

Upvotes: 5

Related Questions