It works as the command manger to execute the command the WPF and the windows 7 phone also it works in the SIlverlight application. The script will stop the garbage collection of the execute command and then can able to run the CanExecuteCommand in any interface. Recommend you to go through the script, it will mijght be help you to execute the command.
Code:
Private Class Handler
Private Shared _Count As Integer = 0
Private _Index As Integer
Public Sub New()
MyBase.New()
_Count += 1
_Index = _Count
Debug.Print("{0} {1} Constructed", Me.GetType.Name, _Index)
End Sub
Protected Overrides Sub Finalize()
Debug.Print("{0} {1} Finalized", Me.GetType.Name, _Index)
MyBase.Finalize()
End Sub
Public Sub OnRequerySuggested(ByVal sender As Object, ByVal e As EventArgs)
Debug.Print("RequerySuggested fired")
End Sub
Public Function CanExecute(ByVal parameter As Object) As Boolean
Debug.Print("{0}.CanExecute called on instance {1}.", Me.GetType.Name, _Index)
Return True
End Function
Public Sub Execute(ByVal parameter As Object)
Debug.Print("{0}.Execute called on instance {1}.", Me.GetType.Name, _Index)
End Sub
End Class
Private Sub AddCommand_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim handler As Handler = New Handler
Dim command As RelayCommand = New RelayCommand(AddressOf handler.Execute, AddressOf handler.CanExecute)
CommandButton.Command = command
End Sub
Bookmarks