我在我的WCF中使用Linq to SQL类。这些类从WCF方法返回到Silverlight。现在,我想在生成的类(Silverlight端)上添加一个自定义属性,并根据另一个属性中的另一个PropertyChangedEvent在该特定属性上触发PropertyChangedEvent。要清楚,这是一段不起作用的代码:
Partial Public Class DataConnection
Public Sub New()
AddHandler Me.PropertyChanged, AddressOf _PropertyChanged
End Sub
Private Sub _PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
If e.PropertyName = "ConnectionType" Then
Me.RaisePropertyChanged("ConnectionTypeEnum")
End If
End Sub
Private _ConnectionTypeEnum As String
Public ReadOnly Property ConnectionTypeEnum() As String
Get
Select Case Me.ConnectionType
Return //Something based on ConnectionType //
End Select
End Get
End Property
End Class
问题是New()中的代码永远不会被执行,因此我永远不知道ConnectionType何时被更改,因此我无法在ConnectionTypeEnum上触发PropertyChanged。 (此属性用于单向绑定,因此我需要它)
有人有解决方案吗?
由于
答案 0 :(得分:2)
<OnDeserializedAttribute()> _
Public Sub WhenDeserialized(context As StreamingContext)
AddHandler Me.PropertyChanged, AddressOf _PropertyChanged
End Sub