wpf - WPF 文本框绑定。VB.Net 2017
问题描述
场景:结构与索引随机访问文件相关联。
在启动时从构造函数中的文件加载数据,并自动为结构分配文件中的数据值,并自动填充 WPF 窗口中的文本框。如果用户在文本框中输入新值,结构也会更新。到目前为止,一切都很好。
当程序运行时用户从文件加载不同的数据集时,就会出现问题。这发生在按钮单击事件中。结构已更新,但此更改未反映在文本框中。
希望有人能对此有所了解。
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}"
解决方案
您的“设置”属性需要调用 PropertyChanged 事件,以便数据绑定更新。
推荐阅读
- php - Simplepie 不显示 RSS 提要
- angular - ngx-perfect-scrollbar 显示隐藏页脚
- c++ - 如何在 C++ 中的 lambda 函数中传递同名的局部变量和参数(使用 this 关键字)?
- reactjs - 在Material-Table中重新排序后是否可以获得当前页面数据?
- sql - 如何在plsql函数中查找包含字符串的行
- linux-kernel - 是否可以“拦截”进程的读/写?
- reinforcement-learning - RL Card Game DQN 上的预测输出为 NaN
- c# - 如何以干净的方式解决处理程序
- python - ProgrammingError: 1064 在使用 django 和 mysql 数据库执行 inspectdb 时
- ios - 如何以编程方式在 iOS 上的当前 Crashlytics (3.14.*) / Firebase (1.10.*) 中禁用 CrashReporting