码迷,mamicode.com
首页 > Windows程序 > 详细

wpf 事件参数 绑定到viewmdoel

时间:2018-11-03 12:37:51      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:highlight   sealed   ati   bin   rop   wpf   ide   erp   property   

public sealed class EventCommand : TriggerAction<DependencyObject>
    {

        public static readonly DependencyProperty CommandParameterProperty =
            DependencyProperty.Register("CommandParameter", typeof(object), typeof(EventCommand), null);


        public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
            "Command", typeof(ICommand), typeof(EventCommand), null);


        public static readonly DependencyProperty InvokeParameterProperty = DependencyProperty.Register(
            "InvokeParameter", typeof(object), typeof(EventCommand), null);

        private string commandName;

        public object InvokeParameter
        {
            get
            {
                return this.GetValue(InvokeParameterProperty);
            }
            set
            {
                this.SetValue(InvokeParameterProperty, value);
            }
        }


        public ICommand Command
        {
            get
            {
                return (ICommand)this.GetValue(CommandProperty);
            }
            set
            {
                this.SetValue(CommandProperty, value);
            }
        }

        public string CommandName
        {
            get
            {
                return this.commandName;
            }
            set
            {
                if (this.CommandName != value)
                {
                    this.commandName = value;
                }
            }
        }

        public object CommandParameter
        {
            get
            {
                return this.GetValue(CommandParameterProperty);
            }

            set
            {
                this.SetValue(CommandParameterProperty, value);
            }
        }

        public object Sender { get; set; }

        protected override void Invoke(object parameter)
        {
            this.InvokeParameter = parameter;
            if (this.AssociatedObject != null)
            {
                ICommand command = this.Command;
                if ((command != null) && command.CanExecute(this.CommandParameter))
                {
                    command.Execute(this.CommandParameter);
                }
            }
        }
    }
<i:Interaction.Triggers>
    <i:EventTrigger EventName="Drop">
        <cmds:EventCommand CommandName="DropCommand" 
        CommandParameter="{Binding RelativeSource={RelativeSource Self},         Path=InvokeParameter}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>    

  

wpf 事件参数 绑定到viewmdoel

标签:highlight   sealed   ati   bin   rop   wpf   ide   erp   property   

原文地址:https://www.cnblogs.com/nocanstillbb/p/9900016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!