当其中一个字段发生更改时,Fire OnPropertyChanged对整个对象

时间:2012-05-09 12:30:09

标签: wpf vb.net inotifypropertychanged

让我们承认一段代码:

    [...]
    Private _filterContacts As FilterContacts
    Public Property FilterContacts() As FilterContacts
        Get
            Return _filterContacts
        End Get
        Set(ByVal value As FilterContacts)
            _filterContacts = value
            OnPropertyChanged("FilterContacts")                    
        End Set
    End Property

    Private _branchType As Nullable(Of Integer)
    Public Property BranchType As Nullable(Of Integer)
        Get
            Return _branchType
        End Get

        Set(ByVal value As Nullable(Of Integer))
            _branchType = value
            OnPropertyChanged("BranchType")                
        End Set
    End Property
    [...]

    Public Sub SomeSub()
        FilterContacts.BranchType = BranchType
    End Sub

我实际上更改了过滤器的“branchType”,但我希望收到有关FilterContacts已更改的通知,而不仅仅是其中一个字段。可能吗?谢谢!

1 个答案:

答案 0 :(得分:2)

Set(ByVal value As Nullable(Of Integer))
    _branchType = value
    OnPropertyChanged("BranchType")                
    OnPropertyChanged("FilterContacts")      
End Set

或者,如果要使对象上的所有属性无效,只需执行以下操作:

OnPropertyChanged("")