예제 #1
0
 private static void OnCommandChanged(EventToCommand element, DependencyPropertyChangedEventArgs e)
 {
     if (element != null)
     {
         if (e.OldValue != null)
         {
             ((ICommand)e.OldValue).CanExecuteChanged -= element.OnCommandCanExecuteChanged;
         }
         ICommand newValue = (ICommand)e.NewValue;
         if (newValue != null)
         {
             newValue.CanExecuteChanged += element.OnCommandCanExecuteChanged;
         }
         element.EnableDisableElement();
     }
 }
예제 #2
0
 static EventToCommand()
 {
     CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(object), typeof(EventToCommand), new PropertyMetadata(null, delegate(DependencyObject s, DependencyPropertyChangedEventArgs e)
     {
         EventToCommand command = s as EventToCommand;
         if ((command != null) && (command.AssociatedObject != null))
         {
             command.EnableDisableElement();
         }
     }));
     CommandProperty             = DependencyProperty.Register("Command", typeof(ICommand), typeof(EventToCommand), new PropertyMetadata(null, (s, e) => OnCommandChanged(s as EventToCommand, e)));
     MustToggleIsEnabledProperty = DependencyProperty.Register("MustToggleIsEnabled", typeof(bool), typeof(EventToCommand), new PropertyMetadata(false, delegate(DependencyObject s, DependencyPropertyChangedEventArgs e)
     {
         EventToCommand command = s as EventToCommand;
         if ((command != null) && (command.AssociatedObject != null))
         {
             command.EnableDisableElement();
         }
     }));
     EventArgsConverterParameterProperty = DependencyProperty.Register("EventArgsConverterParameter", typeof(object), typeof(EventToCommand), new PropertyMetadata(null));
 }