views:

47

answers:

0

Hi,

I am using a TextWriterProxy in the WPF application as follows:

  TextBlock output = new TextBlock();

  TextWriterProxy proxy = new TextWriterProxy();
  proxy.Add(Console.Out);

  StringBuilder sb = new StringBuilder();
  StringWriter resultStringWriter = new StringWriter(sb);
  proxy.Add(resultStringWriter);
  output.Text = sb.ToString();

However, text block does not show any text. Any idea how to do this integration?

The TextWriterProxy code is as follows:

public class TextWriterProxy : TextWriter {

private List<TextWriter> _writers = new List<TextWriter>();

public override Encoding Encoding { get { return

Encoding.Default; } } // Encoding

public override string NewLine {
  get { return base.NewLine; }
  set {
    foreach (TextWriter tw in _writers)
      tw.NewLine = value;
    base.NewLine = value;
  }
} // NewLine

public void Add(TextWriter writer) {
  if (!_writers.Contains(writer))
    _writers.Add(writer);
} // Add

public bool Remove(TextWriter writer) {
  return _writers.Remove(writer);
} // Remove

public override void Write(char value) {
  foreach (TextWriter tw in _writers)
    tw.Write(value);
  base.Write(value);
} // Write

public override void Close() {
  foreach (TextWriter tw in _writers)
    tw.Close();
  base.Close();
} // Close

protected override void Dispose(bool disposing) {
  foreach (TextWriter tw in _writers)
    tw.Dispose();
  base.Dispose(disposing);
} // Dispose

public override void Flush() {
  foreach (TextWriter tw in _writers)
    tw.Flush();
  base.Flush();
} // Flush

} // TextWriterProxy

Thanks, Miguel