2011-01-03 16 views
5

Se durante il debug si verifica un errore di espressione di associazione, l'errore viene registrato nella finestra Output in Visual Studio. È simile al seguente:Errore di espressione di associazione

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

C'è un modo per trattare questo errore come eccezione non gestito invece? Non voglio che la mia app Silverlight continui a essere eseguita se si è verificato un errore di associazione.

risposta

2

È possibile rilevare gli errori di traccia.
(l'ascoltatore deve essere in DLL esterna.)

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(); 
     } 
    } 
} 

Aggiungi questo al 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> 
+0

non funziona per Silverlight. Nessuna classe TraceListener ... –

+0

@KonstantinSalavatov http://forums.silverlight.net/t/65524.aspx/1 – Avram

+0

Per Avram: non è possibile per Silverlight al momento (SL5) –

Problemi correlati