我的程序有一个问题,它的核心是使用一个类变量来连接、控制和提取名为PowerShape的CAD/CAM软件中的信息。
我想要做的是听这个类变量来检测它的属性中的变化,如果您在Powershape中做一些事情,这些变化就会发生。这将包括在Powershape中更改活动窗口或模型。当进行更改时,类变量正在更新,但我不知道如何检测它。
当声明类变量时,它连接到Powershape,然后您可以访问它的属性:
Dim powershapeRoot As New PSAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance)
Dim PSmodelname = PowershapeRoot.activemodel.name现在我想听听变量属性"PowershapeRoot.activemodel.name“,看看它是否发生了变化。
怎么做?
发布于 2016-03-31 13:58:11
要检测属性中的更改,可以使用INotifyPropertyChanged接口。
您将从MSDN中找到这里文档。
在属性的setter中,需要包含引发事件的代码。您可以在VB.NET中找到以下示例:
Public Class Demo Implements INotifyPropertyChanged
Private nameValue 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 name() As String
Get
Return Me.nameValue
End Get
'Raise the event in the setter
Set(ByVal value As String)
If Not (value = nameValue) Then
Me.nameValue = value
NotifyPropertyChanged("name")
End If
End Set
End Property
End Classhttps://stackoverflow.com/questions/36330599
复制相似问题