• wpf 事件参数 绑定到viewmdoel


    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>    
    

      

  • 相关阅读:
    问世即屠榜的bert
    写给日后面试的小朋友们~
    SQL笔记续补
    《姜子牙》视频笔记
    知识图谱之小米的落地与应用探索
    Pyspark ml
    一个小时学会用 Go 编写命令行工具
    C#设计模式-组合模式(Composite Pattern)
    C#设计模式-桥接模式(Bridge Pattern)
    C#设计模式-装饰器模式(Decorator Pattern)
  • 原文地址:https://www.cnblogs.com/nocanstillbb/p/9900016.html
Copyright © 2020-2023  润新知