我有一个用户控件,它有一些公共属性(如Dirty:boolean)和一个更改该属性的事件(ControlValueChanged)。
我将控件添加到表单中。在表单中我有一个按钮(btnOK),我想将按钮的Enabled属性绑定到Dirty属性。
我读了http://msdn.microsoft.com/en-us/library/ms229614.aspx但是我在实施项目时面临一些问题
我的代码形式为:
btnOK.DataBindings.Add("Enabled", Me.wwdp, "Dirty") 'wwdp is my user 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
我收到错误:输入&#39; CallerMemberName&#39;未定义。
事情是,我还没有在msdn中找到更多东西。
答案 0 :(得分:3)
我很抱歉。 MSDN中的链接用于框架4.5
我找到了正确的http://msdn.microsoft.com/en-us/library/ms184414(v=vs.100).aspx。为我的框架
我解决了这个问题
我要离开这个问题,因为别人觉得它很有用
所以工作代码是:
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