在 Silverlight 中,将自定义属性添加到生成的 Linq 类中管理事件

发布于 2024-10-06 01:05:40 字数 1268 浏览 1 评论 0原文

我在 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

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)

有人有解决方案吗?

谢谢

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
                    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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葮薆情 2024-10-13 01:05:40

您可以使用 OnDeserializedAttribute< /a>

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

You can use OnDeserializedAttribute

<OnDeserializedAttribute()> _
Public Sub WhenDeserialized(context As StreamingContext)
    AddHandler Me.PropertyChanged, AddressOf _PropertyChanged
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文