Created
August 18, 2010 20:49
-
-
Save jagregory/536144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example: | |
public partial class App : Application | |
{ | |
protected override void OnStartup(StartupEventArgs e) | |
{ | |
BindingErrors.Throw(); | |
// app gubbins here | |
} | |
} | |
// code: | |
public static class BindingErrors | |
{ | |
public static void Throw() | |
{ | |
PresentationTraceSources.DataBindingSource.Listeners.Add(new BindingErrorListener | |
{ | |
TraceOutputOptions = TraceOptions.None | |
}); | |
PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Error; | |
} | |
} | |
public class BindingErrorListener : DefaultTraceListener | |
{ | |
readonly StringBuilder builder = new StringBuilder(); | |
public override void Write(string message) | |
{ | |
builder.Append(message); | |
} | |
public override void WriteLine(string message) | |
{ | |
builder.Append(message); | |
var fullMessage = builder.ToString(); | |
builder.Length = 0; | |
throw new BindingException(fullMessage); | |
} | |
} | |
public class BindingException : Exception | |
{ | |
public BindingException(string message) | |
: base(message) | |
{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment