【问题标题】:Fire OnPropertyChanged on the entire object when one of its fields changes当其字段之一发生更改时,在整个对象上触发 OnPropertyChanged
【发布时间】:2012-05-17 23:17:36
【问题描述】:

让我们承认一段代码:

    [...]
    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 已更改,而不仅仅是其中一个字段。可能吗?谢谢!

【问题讨论】:

    标签: wpf vb.net inotifypropertychanged


    【解决方案1】:
    Set(ByVal value As Nullable(Of Integer))
        _branchType = value
        OnPropertyChanged("BranchType")                
        OnPropertyChanged("FilterContacts")      
    End Set
    

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

    OnPropertyChanged("")      
    

    【讨论】:

      猜你喜欢
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-15
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多