zoukankan      html  css  js  c++  java
  • WPF自己定义命令Command


    一、自己定义命令
    自己定义命令必需要实现ICommand接口。例如以下代码所看到的:

    /// <summary>
    /// 自己定义的清除命令。

    光脚丫思考 2014-7-31 06:51:32 /// </summary> public class ClearCommand : ICommand { public bool CanExecute(object parameter) { throw new NotImplementedException(); } /// <summary> /// 当命令可运行状态发生改变时,应激发该事件。 /// </summary> public event EventHandler CanExecuteChanged; /// <summary> /// 命令被运行,运行与业务相关的Clear逻辑。

    /// </summary> /// <param name="parameter">运行命令的目标对象。

    </param> public void Execute(object parameter) { IView view = parameter as IView; if (view != null) view.Clear(); } }


    二、实现自己定义命令源
    自己定义命令源需实现ICommandSource接口。

    /// <summary>
    /// 自己定义命令源。崔有来 2014-7-31 06:54:26
    /// </summary>
    public class MyCommandSource : UserControl, ICommandSource
    {
        public ICommand Command { get; set; }
        public object CommandParameter { get; set; }
        public System.Windows.IInputElement CommandTarget { get; set; }
    
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
    
            // 在命令目标上运行命令。

    if (this.CommandTarget != null && this.Command != null) this.Command.Execute(this.CommandTarget); } }


    三、使用自己定义命令

    ClearCommand ClearCmd = new ClearCommand();
    this.MyCommandSource1.Command = ClearCmd;
    this.MyCommandSource1.CommandTarget = this.MiniView1;




  • 相关阅读:
    tfrecord
    数据挖掘模型中的IV和WOE详解
    GBDT
    tensorflow笔记 :常用函数说明
    GAN
    牛客挑战赛 39 牛牛与序列 隔板法 容斥 dp
    4.19 省选模拟赛 跳跃 倍增 二分 线段树 建图
    牛客挑战赛39 牛牛的等差数列
    luogu P6224 [BJWC2014]数据 KD-tree 标准板子 重构+二维平面内最近最远距离查询
    牛客挑战赛39 D 牛牛的数学题 NTT FMT FWT
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5360864.html
Copyright © 2011-2022 走看看