开发者

In Silverlight, add custom property to a generated Linq class + manage events

开发者 https://www.devze.com 2023-01-29 04:37 出处:网络
I\'m using Linq to SQL classes in my WCF. Those classes are returned from the WCF methods to the Silverlight. Now, I want to add a custom property on a the generated class (Silverlight side) and trigg

I'm using Linq to SQL classes in my WCF. Those classes are returned from the WCF methods to the Silverlight. Now, I want to add a custom property on a the generated class (Silverlight side) and trigger a PropertyChangedEvent on that particular property, based on another PropertyChangedEvent from another property. To be clear, here's a piece of code that doesn't work :

    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
             开发者_JAVA技巧       Return //Something based on ConnectionType //
                End Select
            End Get
        End Property


    End Class

The problem is that the code in New() is never executed, so I never know when the ConnectionType is changed, so I can't trigger the PropertyChanged on ConnectionTypeEnum. (this property is used a in One-Way binding so I need it)

Does anyone have a solution for this ?

Thanks


You can use OnDeserializedAttribute

<OnDeserializedAttribute()> _
Public Sub WhenDeserialized(context As StreamingContext)
    AddHandler Me.PropertyChanged, AddressOf _PropertyChanged
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消