What wrong with the next DataBinding example in the Winforms
(vb.net code):
Public Class Info
Implements INotifyPropertyChanged
Private _Word As string
Public Property Word As String
Get
Return _Word
End Get
Set(value As String)
If value.Equals(_Word) = False Then
_Word = value
Me.NotifyPropertyChanged("Word")
End If
End Set
End Property
Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Public Sub New(newWord As String)
Me.Word = newWord
End Sub
Public Function IsValid() As Boolean
Return (String.IsNullOrEmpty(Me.Word) = False)
End Function
End Class
And code of the form
Public Class frmInfo
Private _info As Info
Public Sub New(inInfo As String)
InitializeComponent()
_info= New Info(inInfo)
End Sub
Private Sub frmInfo_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.txtID.DataBindings.Add("Text", _info, "Word") 'Add DataBinding for Word property
'Binding label Visible property to result of the IsValid function
Dim bind As New Binding("Visible", _info, "Word")
AddHandler bind.Format, Sub(obj As Object, args As ConvertEventArgs) args.Value = _raha.IsValid()
Me.lblEven.DataBindings.Add(bind)
End Sub
End Class