Trace in XAML window class vs. Winforms Form class


  • I've been working through an example from WPF Unleashed (Chapter 3) that utilizes Debug.WriteLine to output the logical and visual trees of a WPF window.  I found some odd behavior and was curious if anyone could shed some light on what's going on.


    If I start with a Winforms app and add a XAML window that is launched from the app's main form, Debug.WriteLine and Trace.WriteLine do not write to the Output window in VS 2005.  The Debug/Trace commands work fine in the main winform class.


    However, if I start a full on WPF app that uses app.xaml etc etc, Debug/Trace work as expected inside the window class.  Is there some 'glue' that isn't happening when starting with a 2.0 winforms app?  Is there a configuration trick to address this?  I tried plugging in some various 'TraceSource' solutions I found in various blogs, but nothing seemed to do the trick.




    Thursday, June 28, 2007 2:01 AM


  • We do have some tracing in WPF, but it's based on custom TraceSource instances and shouldn't interact or interfere with static Trace/Debug classes (more info here). 


    By default, the Trace.Listeners collection should be initialized with an instance of DefaultTraceListener, which by default sends output to the debug console.  Maybe somehow that's not getting initialized, or maybe something is actually clearing it out.  As  workaround, you could try running some code to add it, something like if(Trace.Listeners.Count==0) { Trace.Listeners.Add( new DefaultTraceListener() ); }.


    Monday, July 02, 2007 5:40 PM