.net - 追踪 UI 绑定(bind)错误

标签 .net wpf visual-studio-2013 binding error-handling

请让我开始追踪此错误
问题是我绑定(bind)到很多 FieldValue 并且显然并非所有都失败了,否则我会收到更多这些错误
如何找到引发这些警告的 XAML 绑定(bind)?
哈希是否指向特定的绑定(bind)?

System.Windows.Data Warning: 56 : Created BindingExpression (hash=44291519) for Binding (hash=2717082)
System.Windows.Data Warning: 58 :   Path: 'FieldValue'
System.Windows.Data Warning: 56 : Created BindingExpression (hash=4012957) for Binding (hash=2717082)
System.Windows.Data Warning: 58 :   Path: 'FieldValue'
System.Windows.Data Warning: 62 : BindingExpression (hash=4012957): Attach to System.Windows.Controls.TextBox.Text (hash=30313526)
System.Windows.Data Warning: 67 : BindingExpression (hash=4012957): Resolving source 
System.Windows.Data Warning: 70 : BindingExpression (hash=4012957): Found data context element: TextBox (hash=30313526) (OK)
System.Windows.Data Warning: 78 : BindingExpression (hash=4012957): Activate with root item DocFieldDecimalSV (hash=12144638)
System.Windows.Data Warning: 107 : BindingExpression (hash=4012957):   At level 0 using cached accessor for DocFieldDecimalSV.FieldValue: RuntimePropertyInfo(FieldValue)
System.Windows.Data Warning: 104 : BindingExpression (hash=4012957): Replace item at level 0 with DocFieldDecimalSV (hash=12144638), using accessor RuntimePropertyInfo(FieldValue)
System.Windows.Data Warning: 101 : BindingExpression (hash=4012957): GetValue at level 0 from DocFieldDecimalSV (hash=12144638) using RuntimePropertyInfo(FieldValue): <null>
System.Windows.Data Warning: 80 : BindingExpression (hash=4012957): TransferValue - got raw value <null>
System.Windows.Data Warning: 82 : BindingExpression (hash=4012957): TransferValue - user's converter produced ''
System.Windows.Data Warning: 89 : BindingExpression (hash=4012957): TransferValue - using final value ''

我想我已经找到了
获取对 Get 的调用,如果结果是 Decimal?(null),然后是“获取原始值”的错误
然后它调用转换器
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
    Debug.WriteLine("DecimalNullConverter Convert");
    Decimal? Decimal = (Decimal?)value;
    if (Decimal == null)
        return string.Empty;
    return Decimal.ToString();
}

然后最后两行
所以我认为绑定(bind)只是在调用转换后抛出这些错误以获得 String.Emply

所以我认为他们在警告我可以忽略

我真的认为会有一种直接的方法来查看是什么绑定(bind)引发了警告

最佳答案

将有问题的转换器返工为默认文本“FAIL”,除非有有效数据要转换,否则将返回该文本。返回默认文本而不是 string.empty,然后直观地找到问题。

如果绑定(bind)发生在视觉上无法看到默认文本的位置,请在转换内设置断点并使用以下任一方式确定控件 1) 可能更改/使用带有名称中传递的项目之一的多重绑定(bind)转换器的控制?或 2) 使用/设置 ConverterParameter并将 id 传递给转换以识别特定控件。

或设置 FallbackValue在绑定(bind)上查看是否可以缩小可能的文本框列表。

关于.net - 追踪 UI 绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29883452/

相关文章:

.net - 使用 T4MVC 指定部分 View 路径

c# - 无法使用 MVVM 架构将数据绑定(bind)到文本框?

sql - 如何在 Visual Studio 中的 Sql Server Data Tools Editor 中更改连接

c# - Visual Studio 未将设计器连接到代码隐藏

c# - 根据字符串中定义的数据类型在运行时生成结构

c# - 使用与结构相关的 ref 会导致它存储在堆上吗?

c# - .Net zlib 与 .Net 4.5 一起膨胀

c# - 如何在 ItemsControl 中设置从 ItemTemplate 到托管容器的绑定(bind)? (UWP)

c# - 在 Fluent Ribbon 后台显示按钮

visual-studio - 如何处理新分支上的文件