如何在Silverlight中检测到SetBinding成功或失败? [英] How does one detect SetBinding success or failure in Silverlight?

查看:106
本文介绍了如何在Silverlight中检测到SetBinding成功或失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自C#的简单绑定:

  Binding binding = new Binding(SourceName);
  binding.Mode = BindingMode.TwoWay;
  BindingExpressionBase beb = SetBinding(SourceDependencyProperty, binding);

我想检测SetBinding是否成功。 SetBinding显然知道它何时出现问题,因为它在应用程序运行时在输出窗口中显示跟踪:

I would like to detect whether or not the SetBinding was successful. SetBinding obviously knows when it has an issue because it displays in the Output window tracing when the application is running:

System.Windows.Data错误:BindingExpression路径错误:'InterestRate '在'Tc.Views.TestAccount'上找不到属性...

System.Windows.Data Error: BindingExpression path error: 'InterestRate' property not found on 'Tc.Views.TestAccount' ...

无论SetBinding()是成功还是失败,并且没有抛出异常,BindingExpressionBase在我看来都一样。我也尝试了不同的绑定通知标志值。

The BindingExpressionBase looks the same to me whether SetBinding() succeeds or fails and there is no exception thrown. I tried different values for the binding notification flags as well.

推荐答案

我建议您使用Karl Shiflett的瞥见Silverlight 。 GlimpseService公开了一个API,可让您手动处理所有绑定异常。

I suggest you use Karl Shiflett's Glimpse for Silverlight. The GlimpseService exposes an API that'll allow you to handle any binding exceptions manually.

基本技术非常简单-监听Application.UnhandledException和Application.RootVisual.BindingValidationError,您应该能够拦截绑定错误。

The basic technique is fairly simple - listen to Application.UnhandledException and Application.RootVisual.BindingValidationError and you should be able to intercept binding errors.

这篇关于如何在Silverlight中检测到SetBinding成功或失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆