Finding if databinding failed in code?
I am wiring up a binding in code (NOT in XAML).
Is there any way of determining whether the binding path is valid? The obvious candidate is IsDataBound property, but this is alwa开发者_运维百科ys true even if the path is wrong.
Currently I am fudging it by supplying a fallback value and testing for that, but is there a better way?
If you don't mind upgrading your project to Silverlight 5, check out the Silverlight 5 RC. With SL5 debugging databinding has become a breeze since it enables you to set breakpoints inside your XAML code where the binding happens.
Check out this article for a full overview how this works.
The Output-window of Visual Studio is a good place to start, for a more indepth guide on debugging bindings see this MSDN article.
I guess you could use a ValueConverter, which you can add pretty easily in code to your binding and will let you evaluate what is going on between the source and target properties.
精彩评论