[VS 2008+] Class Strings with OnChange Event
This is just a simple little thing cause i'm bored at work and i figure it could be helpful to ppl later, as figuring this out was very helpful to me long ago, and now i almost never make a class without it.
code Code:
'Needed for Implementing the Inotify change event
Imports System.ComponentModel
Public Class Class1
Implements INotifyPropertyChanged
#Region "Inotify"
''' <summary>
''' Duh? the sub Value for our String Property
''' </summary>
''' <remarks></remarks>
Private _strValue As String
''' <summary>
''' The Stringed Property to watch
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Property strValue As String
Get
Return _strValue
End Get
Set(ByVal value As String)
'No need to change it if it's still the same
If _strValue <> value Then
_strValue = value
' Raise the Event Flag!
OnPropertyChanged(value)
End If
End Set
End Property
''' <summary>
''' Establish the event
''' </summary>
''' <remarks></remarks>
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
''' <summary>
''' Sub to run on the event
''' </summary>
''' <param name="name"></param>
''' <remarks></remarks>
Sub OnPropertyChanged(ByVal name As String)
Dim handler As PropertyChangedEventHandler = PropertyChangedEvent
If handler IsNot Nothing Then
handler(Me, New PropertyChangedEventArgs(name))
End If
End Sub
' Dim your class with events and walla
#End Region
End Class
' Dim your class with events and walla