场景: 结构与索引的随机访问文件相关联。
在启动时从构造函数中的文件中加载数据,并自动从文件中为结构分配数据值,并自动填充WPF窗口中的文本框。 如果用户在文本框中输入新值,则结构也会更新。到目前为止一切顺利。
当程序运行时,用户从文件加载了不同的数据集时,就会出现问题。这发生在Button Click事件中。结构已更新,但此更改未反映在文本框中。
有人希望对此有所启发。
WPF和VB.Net都相当新
Public Class MainWindow
Shared myStruct As aStruct
Public Structure aStruct
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public year As Integer
Public Property YearP As Integer
Get
Return myStruct.year
End Get
Set(value As Integer)
myStruct.year = value
End Set
End Property
Public salary as Integer
Public Property SalaryP As Integer
Get
Return myStruct.salary
End Get
Set(value As Integer)
myStruct.salary = value
End Set
End Property
.......
.......
End Structure
Public Sub New()
Me.New(".\indxfile.ptx", ".\datafile.dat")
' This call is required by the designer.
'InitializeComponent() ' Moved
' Add any initialization after the InitializeComponent() call.
End Sub
Public Sub New(Optional _IndexFileName As String = "", Optional _DataFileName As String = "")
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.DataContext = myStruct
Dim Retval As Integer
Retval = GetRecord(2018, DataFileName, Len(myStruct), myStruct, IndexFilename)
If Retval <> 0 Then
MsgBox("Error")
End If
End Class
<TextBox x:Name="Year" Text = "{Binding YearP, Mode = TwoWay}"
答案 0 :(得分:0)
您的“设置”属性需要调用PropertyChanged事件,以便更新数据绑定。