I have a "partial" class in VB.NET. Half of it is automatically generated by the code generation tool. This half implements INotifyPropertyChanged, so any properties in this part of the partial class raise the PropertyChanged event.
In my “custom” part of the class, I declare another property that depends on one of the properties on the automatically generated side. Therefore, when this automatically generated property changes, I also want to raise the PropertyChanged event with my custom property, which depends on it.
If I go into the generated part of the class and raise an event there, it will be overwritten if I ever regenerate this part, so I do not want to do this. I would rather add an event handler to my side of the partial class, which checks to see if the generated property has changed, and if so, raise another event for my custom property.
I am trying to write this to bind my own event, but it does not work:
Private Sub MyProperty_PropertyChangedHandler( _
ByVal sender As Object, ByVal e As PropertyChangedEventArgs _
) Handles Me.PropertyChanged
Select Case e.PropertyName
Case "AutoGenProperty"
RaiseEvent PropertyChanged(Me, _
New PropertyChangedEventArgs("MyProperty"))
End Select
End Sub
I guess this is because you usually use the WithEvents keyword to tell the compiler that you are subscribing to events from this object. I don’t know how to do this inside a class that really raises an event, or if it is possible.
source
share