I want to use a method which is not in the code behind for the command's Executed
event and another for the CanExecute
.
I'm using a RoutedCommand
and i do NOT want to use a Delegate Command or a Relay Command.
What I got is a Commands class:
public class Commands
{
static Commands()
{
syncCommand = new RoutedUICommand("Sync", "syncCommand", typeof(Commands));
undoCommand = new RoutedUICommand("Undo", "UndoCommand", typeof(Commands));
}
private static MyHandler handler;
public static MyHandler Handler
{
set { handler = value; }
get { return handler; }
}
private static RoutedUICommand syncCommand;
public static RoutedUICommand SyncCommand
{
get
{ return syncCommand; }
}
private static void SyncCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = Handler != null;
}
private static void SyncExecute(object sender, ExecutedRoutedEventArgs e)
{
Handler.Action();
}
private static RoutedUICommand undoCommand;
public static RoutedUICommand UndoCommand
{
get { return undoCommand; }
}
private static void UndoCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = Handler.WereChangesMade();
}
private static void UndoExecute(object sender, ExecutedRoutedEventArgs e)
{
Handler.Undo();
}
}
And in the ViewModel I got the ICommand properties and buttons with the Command property that binds to these properties.
I want to use the above methods as the methods I'll pass to the Command Binding. How do I do it when they're not in the code behind?