将 WPF 绑定错误转换为运行时异常.不适用于已发布的已发布应用 [英] Turn WPF Binding error into runtime exception. Not working on published Released app
问题描述
我想将数据绑定错误记录到文件中.我使用了这个公认的 anwser 中提供的解决方案:
I would like to log the DataBinding errors to a file. I Used the solution presented in this accepted anwser:
我也试过这个:http://msdn.microsoft.com/en-us/library/system.diagnostics.presentationtracesources.aspx
问题是它只能在 VS IDE 中运行时才有效.当我发布应用程序时,错误不会出现.
The problem is that it only works while running in the VS IDE. When I publish the app the errors are not caugth.
有谁知道如何在运行时通过已发布的应用程序以编程方式获取 WPF Bindind 错误并保存到文件中?
Does anybody know how to get the WPF Bindind errors and save to a file, by the published app, programatically, during runtime ?
推荐答案
我使用了一种类似于您提供的第一个链接中描述的技术.可以通过以下步骤恢复:
I used a technique similar to the one described in the first link you provided. It can be resumed by the following steps:
- 派生一个
TraceListener
抛出而不是记录 - 将您的侦听器添加到
PresentationTraceSources.DataBindingSource
- Derive a
TraceListener
that throws instead of logging - Add your listener to
PresentationTraceSources.DataBindingSource
我使用 .NET Framework 4.0、4.5 和 4.5.1 进行了测试;它适用于 Debug
和 Release
配置.
I tested with .NET Framework 4.0, 4.5 and 4.5.1; it works on both Debug
and Release
configurations.
请查看我在 GitHub 上推送的完整解决方案,它包括一个演示应用程序和一个单元测试项目.
Please check the complete solution I pushed on GitHub, it includes a demo application and a unit test project.
这篇关于将 WPF 绑定错误转换为运行时异常.不适用于已发布的已发布应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!