gpt4 book ai didi

.net - vb.net 中的变量/属性更改事件

转载 作者:行者123 更新时间:2023-12-04 15:52:57 24 4
gpt4 key购买 nike

如何创建在更改变量或属性时引发的事件(或者我可以将要放入事件的代码放在属性的 Set 部分?

最佳答案

来自 MSDN library entry INotifyPropertyChanged.PropertyChanged Event :

Public Class DemoCustomer
Implements INotifyPropertyChanged

Private customerNameValue As String = String.Empty

Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged

Private Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub

Public Property CustomerName() As String
Get
Return Me.customerNameValue
End Get

Set(ByVal value As String)
If Not (value = customerNameValue) Then
Me.customerNameValue = value
NotifyPropertyChanged("CustomerName")
End If
End Set
End Property
End Class

关于.net - vb.net 中的变量/属性更改事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1996051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com