在 Silverlight 中,将自定义属性添加到生成的 Linq 类中管理事件
我在 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 SubPrivate 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 OnDeserializedAttribute< /a>
You can use OnDeserializedAttribute