Beispiel #1
0
 private ActionBase(string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour, ILogger logger)
 {
     this.MethodName                 = methodName ?? throw new ArgumentNullException(nameof(methodName));
     this.TargetNullBehaviour        = targetNullBehaviour;
     this.ActionNonExistentBehaviour = actionNonExistentBehaviour;
     this.logger = logger;
 }
Beispiel #2
0
        /// <summary>
        /// Initialises a new instance of the <see cref="EventAction"/> class
        /// </summary>
        /// <param name="subject">View whose View.ActionTarget we watch</param>
        /// <param name="backupSubject">Backup subject to use if no ActionTarget could be retrieved from the subject</param>
        /// <param name="eventHandlerType">Type of event handler we're returning a delegate for</param>
        /// <param name="methodName">The MyMethod in {s:Action MyMethod}, this is what we call when the event's fired</param>
        /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
        /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
        public EventAction(DependencyObject subject, DependencyObject backupSubject, Type eventHandlerType, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour)
            : base(subject, backupSubject, methodName, targetNullBehaviour, actionNonExistentBehaviour, logger)
        {
            if (targetNullBehaviour == ActionUnavailableBehaviour.Disable)
                throw new ArgumentException("Setting NullTarget = Disable is unsupported when used on an Event");
            if (actionNonExistentBehaviour == ActionUnavailableBehaviour.Disable)
                throw new ArgumentException("Setting ActionNotFound = Disable is unsupported when used on an Event");

            this.eventHandlerType = eventHandlerType;
        }
Beispiel #3
0
        /// <summary>
        /// Initialises a new instance of the <see cref="ActionBase"/> class to use an explicit target
        /// </summary>
        /// <param name="target">Target to find the method on</param>
        /// <param name="methodName">Method name. the MyMethod in Buttom Command="{s:Action MyMethod}".</param>
        /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
        /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
        /// <param name="logger">Logger to use</param>
        public ActionBase(object target, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour, ILogger logger)
            : this(methodName, targetNullBehaviour, actionNonExistentBehaviour, logger)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            this.Target = target;
        }
Beispiel #4
0
 private static void AssertBehaviours(ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour)
 {
     if (targetNullBehaviour == ActionUnavailableBehaviour.Disable)
     {
         throw new ArgumentException("Setting NullTarget = Disable is unsupported when used on an Event");
     }
     if (actionNonExistentBehaviour == ActionUnavailableBehaviour.Disable)
     {
         throw new ArgumentException("Setting ActionNotFound = Disable is unsupported when used on an Event");
     }
 }
Beispiel #5
0
        /// <summary>
        /// Initialises a new instance of the <see cref="ActionBase"/> class
        /// </summary>
        /// <param name="subject">View to grab the View.ActionTarget from</param>
        /// <param name="backupSubject">Backup subject to use if no ActionTarget could be retrieved from the subject</param>
        /// <param name="methodName">Method name. the MyMethod in Buttom Command="{s:Action MyMethod}".</param>
        /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
        /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
        /// <param name="logger">Logger to use</param>
        public ActionBase(DependencyObject subject, DependencyObject backupSubject, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour, ILogger logger)
        {
            this.Subject                    = subject;
            this.MethodName                 = methodName;
            this.TargetNullBehaviour        = targetNullBehaviour;
            this.ActionNonExistentBehaviour = actionNonExistentBehaviour;
            this.logger = logger;

            // If a 'backupSubject' was given, bind both that and 'subject' to this.Target (with a converter which picks the first
            // one that isn't View.InitialActionTarget). If it wasn't given, just bind 'subject'.

            var actionTargetBinding = new Binding()
            {
                Path   = new PropertyPath(View.ActionTargetProperty),
                Mode   = BindingMode.OneWay,
                Source = this.Subject,
            };

            if (backupSubject == null)
            {
                BindingOperations.SetBinding(this, targetProperty, actionTargetBinding);
            }
            else
            {
                var multiBinding = new MultiBinding();
                multiBinding.Converter = new MultiBindingToActionTargetConverter();
                multiBinding.Bindings.Add(actionTargetBinding);
                multiBinding.Bindings.Add(new Binding()
                {
                    Path   = new PropertyPath(View.ActionTargetProperty),
                    Mode   = BindingMode.OneWay,
                    Source = backupSubject,
                });
                BindingOperations.SetBinding(this, targetProperty, multiBinding);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Initialises a new instance of the <see cref="ActionBase"/> class
        /// </summary>
        /// <param name="subject">View to grab the View.ActionTarget from</param>
        /// <param name="backupSubject">Backup subject to use if no ActionTarget could be retrieved from the subject</param>
        /// <param name="methodName">Method name. the MyMethod in Buttom Command="{s:Action MyMethod}".</param>
        /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
        /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
        /// <param name="logger">Logger to use</param>
        public ActionBase(DependencyObject subject, DependencyObject backupSubject, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour, ILogger logger)
        {
            this.Subject = subject;
            this.MethodName = methodName;
            this.TargetNullBehaviour = targetNullBehaviour;
            this.ActionNonExistentBehaviour = actionNonExistentBehaviour;
            this.logger = logger;

            // If a 'backupSubject' was given, bind both that and 'subject' to this.Target (with a converter which picks the first
            // one that isn't View.InitialActionTarget). If it wasn't given, just bind 'subject'.

            var actionTargetBinding = new Binding()
            {
                Path = new PropertyPath(View.ActionTargetProperty),
                Mode = BindingMode.OneWay,
                Source = this.Subject,
            };

            if (backupSubject == null)
            {
                BindingOperations.SetBinding(this, targetProperty, actionTargetBinding);
            }
            else
            {
                var multiBinding = new MultiBinding();
                multiBinding.Converter = new MultiBindingToActionTargetConverter();
                multiBinding.Bindings.Add(actionTargetBinding);
                multiBinding.Bindings.Add(new Binding()
                {
                    Path = new PropertyPath(View.ActionTargetProperty),
                    Mode = BindingMode.OneWay,
                    Source = backupSubject,
                });
                BindingOperations.SetBinding(this, targetProperty, multiBinding);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Initialises a new instance of the <see cref="CommandAction"/> class
 /// </summary>
 /// <param name="subject">View to grab the View.ActionTarget from</param>
 /// <param name="backupSubject">Backup subject to use if no ActionTarget could be retrieved from the subject</param>
 /// <param name="methodName">Method name. the MyMethod in Buttom Command="{s:Action MyMethod}".</param>
 /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
 /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
 public CommandAction(DependencyObject subject, DependencyObject backupSubject, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour)
     : base(subject, backupSubject, methodName, targetNullBehaviour, actionNonExistentBehaviour, logger)
 {
 }
Beispiel #8
0
 /// <summary>
 /// Initialises a new instance of the <see cref="CommandAction"/> class
 /// </summary>
 /// <param name="subject">View to grab the View.ActionTarget from</param>
 /// <param name="backupSubject">Backup subject to use if no ActionTarget could be retrieved from the subject</param>
 /// <param name="methodName">Method name. the MyMethod in Buttom Command="{s:Action MyMethod}".</param>
 /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
 /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
 public CommandAction(DependencyObject subject, DependencyObject backupSubject, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour)
     : base(subject, backupSubject, methodName, targetNullBehaviour, actionNonExistentBehaviour, logger)
 {
 }
Beispiel #9
0
        /// <summary>
        /// Initialises a new instance of the <see cref="EventAction"/> class
        /// </summary>
        /// <param name="subject">View whose View.ActionTarget we watch</param>
        /// <param name="backupSubject">Backup subject to use if no ActionTarget could be retrieved from the subject</param>
        /// <param name="eventHandlerType">Type of event handler we're returning a delegate for</param>
        /// <param name="methodName">The MyMethod in {s:Action MyMethod}, this is what we call when the event's fired</param>
        /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
        /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
        public EventAction(DependencyObject subject, DependencyObject backupSubject, Type eventHandlerType, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour)
            : base(subject, backupSubject, methodName, targetNullBehaviour, actionNonExistentBehaviour, logger)
        {
            if (targetNullBehaviour == ActionUnavailableBehaviour.Disable)
            {
                throw new ArgumentException("Setting NullTarget = Disable is unsupported when used on an Event");
            }
            if (actionNonExistentBehaviour == ActionUnavailableBehaviour.Disable)
            {
                throw new ArgumentException("Setting ActionNotFound = Disable is unsupported when used on an Event");
            }

            this.eventHandlerType = eventHandlerType;
        }
Beispiel #10
0
 /// <summary>
 /// Initialises a new instance of the <see cref="CommandAction"/> class to use an explicit target
 /// </summary>
 /// <param name="target">Target to find the method on</param>
 /// <param name="methodName">Method name. the MyMethod in Buttom Command="{s:Action MyMethod}".</param>
 /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
 /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
 public CommandAction(object target, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour)
     : base(target, methodName, targetNullBehaviour, actionNonExistentBehaviour, logger)
 {
 }
Beispiel #11
0
 /// <summary>
 /// Initialises a new instance of the <see cref="EventAction"/> class to use an explicit target
 /// </summary>
 /// <param name="target">Target to find the method on</param>
 /// <param name="eventHandlerType">Type of event handler we're returning a delegate for</param>
 /// <param name="methodName">The MyMethod in {s:Action MyMethod}, this is what we call when the event's fired</param>
 /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
 /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
 public EventAction(object target, Type eventHandlerType, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour)
     : base(target, methodName, targetNullBehaviour, actionNonExistentBehaviour, logger)
 {
     AssertBehaviours(targetNullBehaviour, actionNonExistentBehaviour);
     this.eventHandlerType = eventHandlerType;
 }
Beispiel #12
0
 /// <summary>
 /// Initialises a new instance of the <see cref="EventAction"/> classto use <see cref="View.ActionTargetProperty"/> to get the target
 /// </summary>
 /// <param name="subject">View whose View.ActionTarget we watch</param>
 /// <param name="backupSubject">Backup subject to use if no ActionTarget could be retrieved from the subject</param>
 /// <param name="eventHandlerType">Type of event handler we're returning a delegate for</param>
 /// <param name="methodName">The MyMethod in {s:Action MyMethod}, this is what we call when the event's fired</param>
 /// <param name="targetNullBehaviour">Behaviour for it the relevant View.ActionTarget is null</param>
 /// <param name="actionNonExistentBehaviour">Behaviour for if the action doesn't exist on the View.ActionTarget</param>
 public EventAction(DependencyObject subject, DependencyObject backupSubject, Type eventHandlerType, string methodName, ActionUnavailableBehaviour targetNullBehaviour, ActionUnavailableBehaviour actionNonExistentBehaviour)
     : base(subject, backupSubject, methodName, targetNullBehaviour, actionNonExistentBehaviour, logger)
 {
     AssertBehaviours(targetNullBehaviour, actionNonExistentBehaviour);
     this.eventHandlerType = eventHandlerType;
 }