使用枚举属性创建INotifyPropertyChanged接口 [英] Creating a INotifyPropertyChanged Interface with a enum property
本文介绍了使用枚举属性创建INotifyPropertyChanged接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用INotifyPropertyChanged接口创建一个类,但是我很努力..我可以找到很好的例子,但是我的情况略有不同.我发现的所有示例都基于字符串数据,但是在我的示例中,我使用Enum作为数据类型.
I'm trying to create a class with a INotifyPropertyChanged Interface but i'm struggling.. I can find good examples, but my case is slightly different. All examples I find are based on string data, but in my example I use a Enum as datatype.
有人可以帮助我在此示例上实现INotifyPropertyChanged接口吗?
Can someone please help me implement the INotifyPropertyChanged Interface on this example?
Here is the HOW-TO documentation but I can't seem to get this rolling.. Link
Public Class Form1
Private Enum GenderEnum
Male
Female
End Enum
Private Class Person
Public Property Gender As GenderEnum
End Class
End Class
推荐答案
尝试一下,不使用INotifyPropertyChanged 界面
Try this, does not use INotifyPropertyChanged interface
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim p As New Person With {.Gender = GenderEnum.Female}
p.Gender = GenderEnum.Male
End Sub
Private Enum GenderEnum
Male
Female
End Enum
Private Class Person
Private _gender As GenderEnum
Public Property Gender As GenderEnum
Set(value As GenderEnum)
_gender = value
NotifyPropertyChanged("Gender")
End Set
Get
Return _gender
End Get
End Property
Private Sub NotifyPropertyChanged(sender As String)
If sender = "Gender" Then
Console.WriteLine(
性别:{Gender.ToString}") 万一 结束子 末级 末级
"Gender: {Gender.ToString}") End If End Sub End Class End Class
这篇关于使用枚举属性创建INotifyPropertyChanged接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文