gpt4 book ai didi

.NET WPF XAML "BindingExpression path error: ... property not found"

转载 作者:行者123 更新时间:2023-12-01 00:07:49 26 4
gpt4 key购买 nike

我试图将我的 W3CError 类型对象的集合绑定(bind)到 WPF ListView 控件。

这是一个不错的 13 行小类...

类 W3CError

公共(public)类型为 ErrorOrWarning
公共(public)线路为整数
公共(public)列作为整数
公共(public)消息作为字符串
公共(public) MessageId 作为字符串
作为字符串的公共(public)解释
公共(public)源作为字符串

枚举错误或警告
验证错误
验证警告
结束枚举

结束类

它没有用。我在 Visual Studio 的输出窗口中遇到了这些绑定(bind)错误:

System.Windows.Data Error: 39 : BindingExpression path error: 'Line' property not found on 'object' ''W3CError' (HashCode=...)'. BindingExpression:Path=Line; DataItem='W3CError' (HashCode=...); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')



嗯,不,这不是一个属性。它只是公共(public)的。我想这对于 WPF 绑定(bind)还不够好?

我通过将我的类(class)延长到丑陋的 69 行属性样板来让它工作......

类 W3CError

Private _Type 为 ErrorOrWarning
Private _Line 作为整数
私有(private) _Col 作为整数
私有(private) _Message 作为字符串
私有(private) _MessageId 作为字符串
Private _Explanation 作为字符串
私有(private) _Source 作为字符串

枚举错误或警告
验证错误
验证警告
结束枚举

公共(public)属性类型()作为 ErrorOrWarning
得到
返回 _Type
结束获取
设置(ByVal 值作为 ErrorOrWarning)
_Type = 值
结束集
结束属性

公共(public)属性(property)线()作为整数
得到
返回_行
结束获取
设置(ByVal 值作为整数)
_Line = 值
结束集
结束属性

公共(public)属性 Col() 作为整数
得到
返回_Col
结束获取
设置(ByVal 值作为整数)
_Col = 值
结束集
结束属性

公共(public)属性 Message() 作为字符串
得到
返回_Message
结束获取
设置(ByVal 值作为字符串)
_Message = 值(value)
结束集
结束属性

公共(public)属性 MessageId() 作为字符串
得到
返回_MessageId
结束获取
设置(ByVal 值作为字符串)
_MessageId = 值
结束集
结束属性

公共(public)属性说明()作为字符串
得到
返回_说明
结束获取
设置(ByVal 值作为字符串)
_解释=值(value)
结束集
结束属性

公共(public)属性 Source() 作为字符串
得到
返回_Source
结束获取
设置(ByVal 值作为字符串)
_来源 = 值(value)
结束集
结束属性

结束类

有没有更好的办法?

最佳答案

如果您使用的是 C#,我会说使用自动属性,但我认为它们不在 VB 中。

所以可能不会。您甚至可能想要更进一步,让您的类实现 INotifyPropertyChanged,以便您的 UI 知道属性是否更改。

关于.NET WPF XAML "BindingExpression path error: ... property not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/632012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com