zoukankan      html  css  js  c++  java
  • 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>    
    

      

  • 相关阅读:
    理解ORM的前提:数据库中的范式和约束
    C#复习笔记(4)--C#3:革新写代码的方式(查询表达式和LINQ to object(下))
    设置或者得到CheckBoxList选中了的值
    Gridview中Datakeys 通过主键取得各列的值。
    如何直接在网页中显示PDF文件
    C#日期格式化
    asp.net 基础知识
    WebServers 异步
    asp.net中异步调用webservice
    C#中哈希表(HashTable)的用法详解
  • 原文地址:https://www.cnblogs.com/nocanstillbb/p/9900016.html
Copyright © 2011-2022 走看看