简体   繁体   中英

WPF Visual Studio Debug - Console

Today I've ran into a strange thing while testing my WPF app. Visual Studio was in Debug mode. I've created a routed event handler method and wanted to test if the calling was being done correctly, so I put Console.WriteLine("test"); into that method and I was expecting to see the output (the "test" word) in the Output window of the Visual Studio. There didn't appear anything, but I think it should have (tested later on by showing a MessageBox).

I thought it should have appeared, because before this, I was using Console class to display messages to the output window, and it did allways work. So it quite surprise me, because this exact thing worked for me beforehand!

I found a "sollution", switching the project setting "Output type" to "Console App", but, as I expected, a Consolle appeared on the start of the application.

Could anyone please explain me how does the Console methods work in wpf apps in the default setting, and possibly what to use for the correct behaviour in the debugging?

I suggest you use the System.Diagnostics.Debug.WriteLine(); The output will display in the output window inside of VS directly.

Of course, you could also create a Console window manually before you actually call any Console.Write methods:

No output to console from a WPF application?

Console.Writeline works fine in vs2017, not working in vs2019. (tested by opening the same project in vs2017)

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