我遇到了一些奇怪的行为。我有一个控件绑定到这样的属性:
<HyperlinkButton x:Name="ProjectBeheerLink"
Visibility="{Binding IsBeheerder, Converter={StaticResource VisibilityConverter}}"/>
在我的viewmodel中,我的属性实现如下:
Public ReadOnly Property IsBeheerder As Boolean
Get
Return iwtApp.AllMyFunctieRollen.Any(Function(x) x.Rol.Equals(Constants.RoleBeheerder))
End Get
End Property
然后当我在回调方法中提升我的PropertyChanged事件时
Private Sub GetMyPersonCompleted(ByVal lo As LoadOperation(Of FunctieRol))
'Init FunctieRollen ect. ...
RaisePropertyChanged(Function() Me.IsBeheerder)
End Sub
我的绑定不会更新。
然而!如果我实现这样的后端字段:
_isBeheerder = iwtApp.AllMyFunctieRollen.Any(Function(x) x.Rol.Equals(Constants.RoleBeheerder))
RaisePropertyChanged(Function() Me.IsBeheerder)
改变我的财产:
Public ReadOnly Property IsBeheerder As Boolean
Get
Return _isBeheerder
End Get
End Property
一切正常......有人可以解释一下这种行为吗?
好奇为什么......
答案 0 :(得分:0)
实现绑定属性的最佳方法如下:
Dim _isBeheerder As Boolean
Public ReadOnly Property IsBeheerder As Boolean
Get
Return _isBeheerder
End Get
Set
If value <> _isBeheerder Then
_isBeheerder = value
RaisePropertyChanged(Function() Me.IsBeheerder)
End If
End Get
End Property
然后在您的服务回调中,您只需设置此属性:
Private Sub GetMyPersonCompleted(ByVal lo As LoadOperation(Of FunctieRol))
IsBeheerder = myNewValue
End Sub