Ejemplo n.º 1
0
        internal static void SetEventBinding(this Window window, string eventName, string commandName)
        {
            Microsoft.Xaml.Behaviors.EventTrigger trigger = new Microsoft.Xaml.Behaviors.EventTrigger(eventName);
            EventToCommand action = new EventToCommand();

            BindingOperations.SetBinding(action, EventToCommand.CommandProperty, new Binding(commandName));
            trigger.Actions.Add(action);
            Interaction.GetTriggers(window).Add(trigger);
        }
Ejemplo n.º 2
0
        private static void OnCommandChanged(
            EventToCommand element,
            DependencyPropertyChangedEventArgs e)
        {
            if (element == null)
            {
                return;
            }

            if (e.OldValue != null)
            {
                ((ICommand)e.OldValue).CanExecuteChanged -= element.OnCommandCanExecuteChanged;
            }

            var command = (ICommand)e.NewValue;

            if (command != null)
            {
                command.CanExecuteChanged += element.OnCommandCanExecuteChanged;
            }

            element.EnableDisableElement();
        }