Exception on binding expression error
If a binding expression error occur during debugging the error is logged into the Output window in Visual Studio. It looks something like this:
System.Windows.Data Error: BindingExpression path error: 'User' propert开发者_如何学Goy not found
on 'MainPageVM' 'MainPageVM' (HashCode=38694667). BindingExpression: Path='User.FullName'
DataItem='MainPageVM' (HashCode=38694667); target element is 'System.Windows.Controls.TextBlock'
Name=''); target property is 'Text' (type 'System.String')..
Is there a way to treat this error as an unhandled exception instead? I don't want my Silverlight app to continue running if a binding error has occurred.
You can catch the trace errors.
(The listener must be in external dll.)
namespace CustomTracer
{
public class CustomTraceListener : TraceListener
{
public CustomTraceListener()
{
}
public override void Write(string message)
{
}
public override void WriteLine(string message)
{
if(Debugger.IsAttached)
Debugger.Break();
}
}
}
Add this to app.config
<system.diagnostics>
<sources>
<source name="System.Windows.Data" switchName="OnlyErrors" >
<listeners>
<add name="textListener" type="CustomTracer.CustomTraceListener,CustomTracer"/>
</listeners>
</source>
</sources>
<switches>
<add name ="OnlyErrors" value ="Error"/>
</switches>
</system.diagnostics>
精彩评论