Пример #1
0
 private CommandSubscription GetOrCreateSubscription(UIElement element)
 {
     CommandSubscription subscription = null;
     if( !_subscriptions.ContainsKey(element) )
     {
         subscription = new CommandSubscription(element);
         _subscriptions[element] = subscription;
     } else
     {
         subscription = _subscriptions[element];
     }
     return subscription;
 }
Пример #2
0
 private void HookupExecuteEvent(CommandSubscription subscription)
 {
     if( subscription.UIElement is ButtonBase )
     {
         HookupExecuteEventForButtonBase(subscription);
     } else if( subscription.UIElement is TextBox )
     {
         HookupExecuteEventForTextBox(subscription);
     } else if( subscription.UIElement is ICanExecuteCommand )
     {
         HookupExecuteEventForRoutedCommand(subscription);
     } else
     {
         HookupExceuteEventForLeftMouseButtonUp(subscription);
     }
 }
Пример #3
0
 private void HookupExecuteEventForTextBox(CommandSubscription subscription)
 {
     var textBox = subscription.UIElement as TextBox;
     textBox.TextChanged += (s, e) => subscription.Execute();
 }
Пример #4
0
 private void HookupExecuteEventForRoutedCommand(CommandSubscription subscription)
 {
     var routedCommand = subscription.UIElement as ICanExecuteCommand;
     routedCommand.Command += (s, e) => subscription.Execute();
 }
Пример #5
0
 private void HookupExecuteEventForButtonBase(CommandSubscription subscription)
 {
     var button = subscription.UIElement as ButtonBase;
     button.Click += (s,e) => subscription.Execute();
 }
Пример #6
0
 private void HookupExceuteEventForLeftMouseButtonUp(CommandSubscription subscription)
 {
     subscription.UIElement.MouseLeftButtonDown += (s, e) => subscription.Execute();
 }
Пример #7
0
 private void HookUpCanExecuteEvent(CommandSubscription subscription)
 {
     subscription.Command.CanExecuteChanged +=
         (s, e) => SetCanExecute(subscription);
 }
Пример #8
0
 private void SetCanExecute(CommandSubscription subscription)
 {
     subscription.UIElement.Dispatcher.BeginInvoke(
         () =>
             {
                 if (subscription.UIElement is Control)
                 {
                     ((Control) subscription.UIElement).IsEnabled = subscription.Command.CanExecute(subscription.CommandParameter);
                 }
                 else if (subscription.UIElement is ICanBeEnabled)
                 {
                     ((ICanBeEnabled) subscription.UIElement).IsEnabled =
                         subscription.Command.CanExecute(subscription.CommandParameter);
                 }
             });
 }