当用户单击从随机访问文件中检索新数据的WPF按钮时,值的结构确实发生变化。 可以同时执行CanExecute和Execute方法。
Q#1: 子执行和属性中需要什么,以使文本框反映结构中的新值?
Q#2: 在程序中如何确定CanExecute应该返回true还是false?
XAML:
<Button Grid.Column="2" Grid.Row="0" Command="{Binding}"
Click="Button_Click" Content="Get Record"/>
VB.NET:
Structure myStruct
Implements ICommand
Implements INotifyPropertyChanged
Public Event CanExecuteChanged As EventHandler Implements ICommand.CanExecuteChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public _element As Integer
Public Property Element As Integer
Get
Return _element
End Get
Set(value As Integer)
_element = value
End Set
End Property
Public Function CanExecute(parameter As Object) As Boolean Implements ICommand.CanExecute
'Throw New NotImplementedException()
'CanExecute = True
MsgBox("CanExecute")
End Function
Public Sub Execute(parameter As Object) Implements ICommand.Execute
'Throw New NotImplementedException()
MsgBox("Execute")
End Sub
End Structure