简体   繁体   中英

printfn and debug output in F# WPF VS2012 project

I'm experimenting with WPF in F#. Visual Studio 2012 has several online project templates for that:

  • F# & C# Hybrid MVVM. Standard C# WPF executable for views and f# libs for the rest.
  • Pure F# MVVM
  • Pure F# Empty

I started with the first option, but later switched to the pure f# solution. And there is one issue I can't get around with.

I don't see the printfn results in the VS Output window anymore. Though if I put a breakpoint I see that the code gets reached.

Here is a sample:

module MainApp
open System
open System.Windows
open System.Windows.Controls
open FSharpx

type MainWindow = XAML<"MainWindow.xaml">

let loadWindow() =
    let window = MainWindow()

    printfn "%s" "Test"

    window.Root

[<STAThread>]
(new Application()).Run(loadWindow()) |> ignore

That's the App.fs created by the template with a single addition - printfn. Output - nothing.

I wonder what's makes it different. Any ideas?

You can use System.Diagnostics.Debug.WriteLine to write to the VS Output window. The TRACE constant must be defined, which it is by default in Debug.

The printfn writes to stdout which is the console window in a console application.

另外,您可以将项目设置为控制台应用程序,这样您将拥有一个控制台窗口以及WPF窗口,并且可以像往常一样使用printfn。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM