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

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

问题描述

C#中的简单绑定:

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

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

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

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的Glimpse 。 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天全站免登陆