如何检测损坏的 WPF 数据绑定? [英] How to detect broken WPF Data binding?

查看:25
本文介绍了如何检测损坏的 WPF 数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试回答附近的问题单元测试 WPF 绑定"时,我有下面是一个棘手的问题..
如果您的 WPF 数据绑定接线设置不正确(或者您只是破坏了正确接线的东西),最好的方法是什么?

While trying to answer a question in the vicinity 'Unit Testing WPF Bindings' I had the following niggling question..
What's the best way to find if you have WPF Data Binding wiring setup incorrectly (or you just broke something that was wired up correctly) ?

尽管单元测试方法似乎就像 Joel 的扯掉你的手臂以去除碎片"一样......我正在四处寻找更简单的方法来检测这一点.

Although the unit-testing approach seems to be like Joel's 'ripping off your arm to remove a splinter'.. I am looking around for easier less Overhead ways to detect this.

似乎每个人都在很大程度上致力于使用 WPF 进行数据绑定......而且它确实有它的优点.

Everyone seems to have committed themselves to data binding in a big way with WPF.. and it does have its merits.

推荐答案

我能找到的最好的...

Best I could find...

由于每个人不能总是盯着输出窗口寻找绑定错误,我喜欢选项#2.这是将它添加到您的 App.Config

Since everyone can't always keep one eye on the Output Window looking for Binding errors, I loved Option#2. Which is add this to your App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.Windows.Data" switchName="SourceSwitch" >
        <listeners>
          <add name="textListener" />
        </listeners>
      </source>

    </sources>
      <switches>
        <add name="SourceSwitch" value="All" />
      </switches>

      <sharedListeners>
        <add name="textListener"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="GraveOfBindErrors.txt" />
      </sharedListeners>

      <trace autoflush="true" indentsize="4"></trace>

  </system.diagnostics>
</configuration>

将它与一个好的正则表达式扫描脚本配对以提取相关信息,您可以偶尔在输出文件夹中的 GraveOfBindErrors.txt 上运行这些信息

Pair that up with a good regex scan script to extract out relevant info, that you can run occasionally on the GraveOfBindErrors.txt in your output folder

System.Windows.Data Error: 35 : BindingExpression path error: 'MyProperty' property not found on 'object' ''MyWindow' (Name='')'. BindingExpression:Path=MyProperty; DataItem='MyWindow' (Name=''); target element is 'TextBox' (Name='txtValue2'); target property is 'Text' (type 'String')

这篇关于如何检测损坏的 WPF 数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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