4 using System.Windows.Input;
5 using System.Windows.Interactivity;
9 namespace SiliconStudio.Presentation.Behaviors
17 private CommandBinding commandBinding;
22 public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
"Command", typeof(
ICommandBase), typeof(
CommandBindingBehavior),
new PropertyMetadata(null, CommandChanged));
27 public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.Register(
"IsEnabled", typeof(
bool), typeof(
CommandBindingBehavior),
new PropertyMetadata(
true));
32 public RoutedCommand RoutedCommand {
get; set; }
37 public ICommandBase Command {
get {
return (
ICommandBase)GetValue(CommandProperty); } set { SetValue(CommandProperty, value); } }
42 public bool IsEnabled {
get {
return (
bool)GetValue(IsEnabledProperty); } set { SetValue(IsEnabledProperty, value); } }
47 commandBinding =
new CommandBinding(RoutedCommand, (
s, e) => OnExecuted(e), (
s, e) => OnCanExecute(e));
48 AssociatedObject.CommandBindings.Add(commandBinding);
54 AssociatedObject.CommandBindings.Remove(commandBinding);
57 private static void CommandChanged(
DependencyObject d, DependencyPropertyChangedEventArgs e)
59 CommandManager.InvalidateRequerySuggested();
62 private void OnCanExecute(CanExecuteRoutedEventArgs canExecuteRoutedEventArgs)
66 canExecuteRoutedEventArgs.CanExecute = IsEnabled && Command.CanExecute(canExecuteRoutedEventArgs.Parameter);
67 canExecuteRoutedEventArgs.Handled =
true;
71 canExecuteRoutedEventArgs.CanExecute =
true;
75 private void OnExecuted(ExecutedRoutedEventArgs executedRoutedEventArgs)
77 if (Command != null && IsEnabled)
79 Command.Execute(executedRoutedEventArgs.Parameter);
80 executedRoutedEventArgs.Handled =
true;
This command will bind a ICommandBase to a RoutedCommand. It works just as a CommandBinding except th...
override void OnDetaching()
An interface representing an implementation of ICommand with additional properties.
override void OnAttached()