1
votes

I have a user control that has some public properties (like Dirty :boolean) and an event (ControlValueChanged) that change that property.
I added that control to a form. In the form I have a button (btnOK) and I want to bind the property Enabled of the button to the Dirty property.
I read http://msdn.microsoft.com/en-us/library/ms229614.aspx but I face some problems to implement this to my project.
My code in the form:

btnOK.DataBindings.Add("Enabled", Me.wwdp, "Dirty") 'wwdp is my user Control

So from my research I have to add in my custom control:

Imports System.ComponentModel

Public Class wwDynamicPanel

Implements INotifyPropertyChanged

Public Event PropertyChanged As PropertyChangedEventHandler _
    Implements INotifyPropertyChanged.PropertyChanged


 Public Property Dirty As Boolean
    Get
        Return mbDirty
    End Get
    Set(ByVal value As Boolean)
        mbDirty = value
        NotifyPropertyChanged()
    End Set

End Property

Private Sub NotifyPropertyChanged(<CallerMemberName()> Optional ByVal propertyName As String = Nothing)
    RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub

I get an error : Type 'CallerMemberName' is not defined.
The thing is that I haven't found in msdn anything more.

1

1 Answers

4
votes

I am very sorry. The link in MSDN was for framework 4.5
I found the right http://msdn.microsoft.com/en-us/library/ms184414(v=vs.100).aspx. for my framework and I solved the problem.
I am leaving the question because someone else find it useful.
So the working code is:

Imports System.ComponentModel

Public Class wwDynamicPanel

Implements INotifyPropertyChanged

Public Event PropertyChanged As PropertyChangedEventHandler _
   Implements INotifyPropertyChanged.PropertyChanged


Public Property Dirty As Boolean
   Get
      Return mbDirty
   End Get
   Set(ByVal value As Boolean)
      mbDirty = value
      NotifyPropertyChanged("Dirty")
   End Set
End Property

Private Sub NotifyPropertyChanged(ByVal info As String)
     RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub