elBee
New member
- Joined
- May 17, 2021
- Messages
- 2
- Programming Experience
- 3-5
Hello together,
I have just started to work with classes and properties and now I am at a point where I don't know if it works or how it works,
I have 2 classes.
Klasse 1 wird einmal instanziert, Klasse 2 kann mehrmals instanziert werden:
My two classes would look like this:
If now in the 1st class the property "Test1" changes, then all instances of the class 2 (in this case the property "Test2" should update.
Is this possible and if so, would someone give me an example of how this works?
It would be very nice if someone could shed some light on this. As I said, I am quite new in this area.
Kind regards,
Sven
I have just started to work with classes and properties and now I am at a point where I don't know if it works or how it works,
I have 2 classes.
Klasse 1 wird einmal instanziert, Klasse 2 kann mehrmals instanziert werden:
VB.NET:
Dim x as New Class 2
Dim y as New Class 2
Dim z as New Class 2
My two classes would look like this:
VB.NET:
Imports System.ComponentModel
' +++ CLASS 1 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Public Class Class1
'INotifyPropertyChanged
Implements INotifyPropertyChanged
Public Shadows Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Private _Test1 As String
Public Property Test1() As Integer
Get
Return _Test1
End Get
Set(value As Integer)
_Test1 = value
NotifyPropertyChanged("Test1")
End Set
End Property
End Class
' +++ CLASS 2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Public Class Class2
'INotifyPropertyChanged
Implements INotifyPropertyChanged
Public Shadows Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Private _Test2 As String
Public Property Test2() As Integer
Get
Return _Test2
End Get
Set(value As Integer)
Dim xyz As Class1
_Test2 = value * xyz.Test1 'HERE IS THE PROBLEM
NotifyPropertyChanged("Test2")
End Set
End Property
End Class
If now in the 1st class the property "Test1" changes, then all instances of the class 2 (in this case the property "Test2" should update.
Is this possible and if so, would someone give me an example of how this works?
It would be very nice if someone could shed some light on this. As I said, I am quite new in this area.
Kind regards,
Sven
Last edited by a moderator: