想出一个解决办法
转到app.xaml.cs文件并重新处理未处理的\u异常函数
有了这个,再加上一点叫这个JS,就很容易了。
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
// If the app is running outside of the debugger then report the exception using
// the browser's exception mechanism. On IE this will display it a yellow alert
// icon in the status bar and Firefox will display a script error.
// NOTE: This will allow the application to continue running after an exception has been thrown
// but not handled.
// For production applications this error handling should be replaced with something that will
// report the error to the website and stop the application.
e.Handled = true;
try
{
ThrowRightError(e.ExceptionObject);
//System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight a 2 Application " + errorMsg + "\");");
}
catch
{
}
}
private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
{
try
{
ThrowRightError(e.ExceptionObject);
//System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
}
catch (Exception)
{
}
}
private void ThrowRightError(Exception e)
{
string errorMsg = "";
var exLayer = -1;
//errorMsg += String.Format("<br>Layer {0}<hr>", exLayer);
Exception ex2 = e;
while (ex2 != null)
{
errorMsg += "Message : <br />" + ex2.Message + "<br />Data :<br />" + ex2.Data + "<br />StackTrace :<br />" + ex2.StackTrace;
exLayer++;
errorMsg += String.Format("<br>Layer {0}<hr>", exLayer);
ex2 = ex2.InnerException;
}
errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"<br />");
HtmlPage.Window.CreateInstance("foo2", new[] { errorMsg });
}
然后为JS
function foo2(theAlert) {
$("#errorLocation").html(theAlert);
}
我还发现了最初的错误是什么
ClientIdTextBlock.SetBinding(TextBox.TextProperty, ClientIdBinding);
文本的文本框绑定
街区
…愚蠢的错误。