Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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' property 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.

like image 899
martin Avatar asked Jan 03 '11 10:01

martin


1 Answers

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>
like image 164
Avram Avatar answered Oct 18 '22 17:10

Avram