标签:style blog color io ar 使用 strong sp 2014
一、自定义命令
自定义命令必须要实现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(); } }
/// <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;
标签:style blog color io ar 使用 strong sp 2014
原文地址:http://blog.csdn.net/gjysk/article/details/40180715