-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBindingErrorTraceListener.cs
More file actions
49 lines (44 loc) · 1.51 KB
/
BindingErrorTraceListener.cs
File metadata and controls
49 lines (44 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Diagnostics;
namespace BytecodeApi.Wpf;
/// <summary>
/// Directs WPF binding error output to event handlers.
/// </summary>
public class BindingErrorTraceListener : TraceListener
{
/// <summary>
/// Occurs when a WPF binding error is traced.
/// </summary>
public event EventHandler<string>? EventReceived;
/// <summary>
/// Initializes a new instance of the <see cref="BindingErrorTraceListener" /> class.
/// </summary>
public BindingErrorTraceListener()
{
TraceSource traceSource = PresentationTraceSources.DataBindingSource;
traceSource.Listeners.Add(this);
traceSource.Switch.Level = SourceLevels.Error;
}
/// <summary>
/// When overridden in a derived class, writes the specified message to the listener you create in the derived class.
/// </summary>
/// <param name="message">A message to write.</param>
public override void Write(string? message)
{
}
/// <summary>
/// When overridden in a derived class, writes a message to the listener you create in the derived class, followed by a line terminator.
/// </summary>
/// <param name="message">A message to write.</param>
public override void WriteLine(string? message)
{
OnEventReceived(message ?? "");
}
/// <summary>
/// Raises the <see cref="EventReceived" /> event.
/// </summary>
/// <param name="message">The message for the <see cref="EventReceived" /> event.</param>
protected virtual void OnEventReceived(string message)
{
EventReceived?.Invoke(this, message);
}
}