<legend id='06N5t'><style id='06N5t'><dir id='06N5t'><q id='06N5t'></q></dir></style></legend>
    • <bdo id='06N5t'></bdo><ul id='06N5t'></ul>

    <small id='06N5t'></small><noframes id='06N5t'>

  1. <i id='06N5t'><tr id='06N5t'><dt id='06N5t'><q id='06N5t'><span id='06N5t'><b id='06N5t'><form id='06N5t'><ins id='06N5t'></ins><ul id='06N5t'></ul><sub id='06N5t'></sub></form><legend id='06N5t'></legend><bdo id='06N5t'><pre id='06N5t'><center id='06N5t'></center></pre></bdo></b><th id='06N5t'></th></span></q></dt></tr></i><div id='06N5t'><tfoot id='06N5t'></tfoot><dl id='06N5t'><fieldset id='06N5t'></fieldset></dl></div>

    1. <tfoot id='06N5t'></tfoot>

    2. 跟踪侦听器以写入文本框(WPF 应用程序)

      Trace listener to write to a text box (WPF application)(跟踪侦听器以写入文本框(WPF 应用程序))

      <small id='OHLAk'></small><noframes id='OHLAk'>

        <bdo id='OHLAk'></bdo><ul id='OHLAk'></ul>
        <i id='OHLAk'><tr id='OHLAk'><dt id='OHLAk'><q id='OHLAk'><span id='OHLAk'><b id='OHLAk'><form id='OHLAk'><ins id='OHLAk'></ins><ul id='OHLAk'></ul><sub id='OHLAk'></sub></form><legend id='OHLAk'></legend><bdo id='OHLAk'><pre id='OHLAk'><center id='OHLAk'></center></pre></bdo></b><th id='OHLAk'></th></span></q></dt></tr></i><div id='OHLAk'><tfoot id='OHLAk'></tfoot><dl id='OHLAk'><fieldset id='OHLAk'></fieldset></dl></div>

        1. <legend id='OHLAk'><style id='OHLAk'><dir id='OHLAk'><q id='OHLAk'></q></dir></style></legend>
              • <tfoot id='OHLAk'></tfoot>
                  <tbody id='OHLAk'></tbody>
                本文介绍了跟踪侦听器以写入文本框(WPF 应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                对于我的 WPF 应用程序,我使用 TextWriterTraceListener 将日志记录到文本文件.如何将 Trace 输出也显示到文本框?

                For my WPF application I do logging to a text file using a TextWriterTraceListener. How can I also display the Trace output to a textbox?

                推荐答案

                我在 C# winforms 中使用这个,应该很容易调整到 wpf

                I use this for C# winforms, should be easily adjustable to wpf

                public class MyTraceListener : TraceListener
                {
                    private TextBoxBase output;
                
                    public MyTraceListener(TextBoxBase output) {
                        this.Name = "Trace";
                        this.output = output;
                    }
                
                
                    public override void Write(string message) {
                
                        Action append = delegate() {
                            output.AppendText(string.Format("[{0}] ", DateTime.Now.ToString()));
                            output.AppendText(message); 
                        };
                        if (output.InvokeRequired) {
                            output.BeginInvoke(append);
                        } else {
                            append();
                        }
                
                    }
                
                    public override void WriteLine(string message) {
                        Write(message + Environment.NewLine);
                    }
                }
                

                像这样使用它

                TraceListener debugListener = new MyTraceListener (theTextBox);
                Debug.Listeners.Add(debugListener);
                Trace.Listeners.Add(debugListener);
                

                记得 Trace/Debug.Listeners.Remove(debugListener);当你不再需要它时.

                Remember to Trace/Debug.Listeners.Remove(debugListener); when you don't need it anymore.

                这篇关于跟踪侦听器以写入文本框(WPF 应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                C# - Add button click events using code(C# - 使用代码添加按钮单击事件)
                Multi-color TextBox C#(多色文本框 C#)
                How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                C# Numeric Only TextBox Control(C# 纯数字文本框控件)
                  <bdo id='ES8mC'></bdo><ul id='ES8mC'></ul>

                    <tbody id='ES8mC'></tbody>

                  <small id='ES8mC'></small><noframes id='ES8mC'>

                • <legend id='ES8mC'><style id='ES8mC'><dir id='ES8mC'><q id='ES8mC'></q></dir></style></legend>
                  <tfoot id='ES8mC'></tfoot>
                  • <i id='ES8mC'><tr id='ES8mC'><dt id='ES8mC'><q id='ES8mC'><span id='ES8mC'><b id='ES8mC'><form id='ES8mC'><ins id='ES8mC'></ins><ul id='ES8mC'></ul><sub id='ES8mC'></sub></form><legend id='ES8mC'></legend><bdo id='ES8mC'><pre id='ES8mC'><center id='ES8mC'></center></pre></bdo></b><th id='ES8mC'></th></span></q></dt></tr></i><div id='ES8mC'><tfoot id='ES8mC'></tfoot><dl id='ES8mC'><fieldset id='ES8mC'></fieldset></dl></div>