WPF使用IDataErrorInfo在View-Model中验证模型对象的属性

时间:2014-01-05 02:52:47

标签: wpf vb.net validation mvvm idataerrorinfo

我是WPF和MVVM的新手,我正在尝试使用IDataErrorInfo进行数据验证。这是场景。我有一个名为Loan的模型。

模型

Public Class Loan
Private _AccountNumber As String

Public Property AccountNumber() As String
    Get
       Return _AccountNumber
    End Get
    Set(ByVal value As String)
       _AccountNumber = value
    End Set
End Property
End Class

视图模型

Public Class LoanViewModel
Implements INotifyPropertyChanged, IDataErrorInfo

Private _Loan As New Loan() ' Loan object
Public Property Loan() As Loan
    Get
       Return _Loan
    End Get
    Set(ByVal value As Loan)
       _Loan = value
    End Set
End Property
End Class

视图

数据上下文设置为LoanViewModel,TextBox绑定到View-Model中贷款对象的属性。

<TextBox Text="{Binding Path=Loan.AccountNumber, ValidatesOnDataErrors=True}" />

我的问题是,如何从我的View-Model验证Loan对象的属性(即AccountNumber)?

0 个答案:

没有答案