Esempio n. 1
0
        /// <summary>
        /// Executes the action.
        /// </summary>
        /// <param name="sender">The <see cref="T:System.Object"/> that is passed to the action by the behavior. Generally this is <seealso cref="P:Microsoft.Xaml.Interactivity.IBehavior.AssociatedObject"/> or a target object.</param><param name="parameter">The value of this parameter is determined by the caller.</param>
        /// <remarks>
        /// An example of parameter usage is EventTriggerBehavior, which passes the EventArgs as a parameter to its actions.
        /// </remarks>
        /// <returns>
        /// Returns the result of the action.
        /// </returns>
        public object Execute(object sender, object parameter)
        {
            ICommand command = Command;

            // Use either our set parameter, or the passed parameter.
            object commandParameter = (base.ReadLocalValue(CommandParameterProperty) != DependencyProperty.UnsetValue)
                ? CommandParameter : parameter;

            // Reach in and get the specific property if we have a path specified
            if (commandParameter != null && CommandParameterPath != null)
            {
                Binding binding = new Binding {
                    Source = commandParameter, Path = CommandParameterPath
                };
                NameScopeBinding nsb = new NameScopeBinding();
                BindingOperations.SetBinding(nsb, NameScopeBinding.SourceProperty, binding);
                commandParameter = nsb.Source;
            }

            if ((command != null) && command.CanExecute(commandParameter))
            {
                command.Execute(commandParameter);
                return(true);
            }

            return(false);
        }
        private void RunPasses(CompilationUnit unit)
        {
            DeclarationBinding sb = container[typeof(DeclarationBinding)] as DeclarationBinding;
            NameScopeBinding   ns = container[typeof(NameScopeBinding)] as NameScopeBinding;

            sb.ExecutePass(unit);
            ns.ExecutePass(unit);
        }
Esempio n. 3
0
        /// <summary>
        /// This is called to execute the command when the trigger conditions are satisfied.
        /// </summary>
        /// <param name="parameter">parameter (not used)</param>
        protected override void Invoke(object parameter)
        {
            ICommand command = Command;
            //TODO: need to find a way to detect Binding here - BindingOperations.IsDataBound
            object commandParameter = CommandParameter ?? parameter;

            // Reach in and get the specific property
            if (commandParameter != null && CommandParameterPath != null)
            {
                Binding binding = new Binding {
                    Source = commandParameter, Path = CommandParameterPath
                };
                NameScopeBinding nsb = new NameScopeBinding();
                BindingOperations.SetBinding(nsb, NameScopeBinding.SourceProperty, binding);
                commandParameter = nsb.Source;
            }

            if ((command != null) && command.CanExecute(commandParameter))
            {
                command.Execute(commandParameter);
            }
        }