且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测损坏的 WPF 数据绑定?

更新时间:2021-12-01 08:45:34

我能找到的***的...

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