WPF 命令类重写 CanExecuteChanged-Event?
目前我有以下 Command 类:
Public Class SubscribeCommand
Implements ICommand
Private ReadOnly _vm As MainWindowViewModel
Public Sub New(ByVal vm As MainWindowViewModel)
_vm = vm
End Sub
Public Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
Return Not String.IsNullOrEmpty(_vm.Symbol)
End Function
Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged
Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
_vm.Subscribe()
End Sub
End Class
在我读过的教程中,您必须为 canExecuteChanged-Event 实现 add {} 和 remove {} 。但是我怎样才能用vb.net做到这一点呢?
多谢..
At the moment I have the following Command class:
Public Class SubscribeCommand
Implements ICommand
Private ReadOnly _vm As MainWindowViewModel
Public Sub New(ByVal vm As MainWindowViewModel)
_vm = vm
End Sub
Public Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
Return Not String.IsNullOrEmpty(_vm.Symbol)
End Function
Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged
Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
_vm.Subscribe()
End Sub
End Class
In a tutorial i read, you have to implement add {} and remove {} for the canExecuteChanged-Event. But how can i do that, with vb.net?
thanks a lot..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不需要为 CanExecuteChanged 事件实现添加和删除部分。我很确定它会按照您现在的方式正常工作。但是,如果您出于某种原因确实想要(使其与您在 C# 中的这篇文章, 例如),您将更
改为
I don't think you're required to implement the add and remove pieces for the CanExecuteChanged event. I'm pretty sure it'll work just fine the way you have it now. But if you did want to for some reason (to make it match what you see in this post in C#, for instance), you would change
to
如果你想在 wpf 中使用命令,请查看那里的 wpf 框架。你会发现至少有两个不错的命令实现:
if you wanna use Commands in wpf please look at the wpf frameworks out there. you will find at least two nice command implementation: