2011-05-20 47 views
0

目前我有以下命令類:WPF命令類重寫CanExecuteChanged-Event?

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的事件。但我怎麼能做到這一點,與VB.NET?

非常感謝..

回答

2

你需要實現添加和移除件爲CanExecuteChanged事件,我不認爲。我很肯定它現在可以正常工作。但是,如果你確實想因爲某些原因(使它與您在this post in C#,例如見),你會改變

Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) 

Public Custom Event CanExecuteChanged As EventHandler 

    AddHandler(ByVal value As EventHandler) 

     CommandManager.RequestSuggested += value 

    End AddHandler 

    RemoveHandler(ByVal value As EventHandler) 

      CommandManager.RequestSuggested -= value 

    End RemoveHandler 

End Event 
+0

不知道我很想念這裏,但我的項目,當我使用這個代碼它不編譯。說調用RaiseEvent代替。 – TWood 2013-09-19 20:03:35