www.pudn.com > SLICommand.zip > btnCommand.cs, change:2012-04-06,size:1576b


using System; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Ink; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
 
namespace SLICommand 
{ 
    public class btnCommand:ICommand 
    { 
        private bool canExe; 
        /// <summary> 
        /// 构造函数设置是否执行操作 
        /// </summary> 
        /// <param name="canexe"></param> 
        public btnCommand(bool canexe) 
        { 
            this.canExe = canexe;  
        } 
 
        /// <summary> 
        /// 判断是否执行操作 
        /// </summary> 
        /// <param name="parameter"></param> 
        /// <returns></returns> 
        public bool CanExecute(object parameter) 
        { 
            if (canExe) 
            { 
                return true;                
            } 
            return false; 
        } 
 
        /// <summary> 
        /// 是否执行操作的变更发生时 
        /// </summary> 
        public event EventHandler CanExecuteChanged; 
 
        /// <summary> 
        /// 执行操作的内容,可以变为Action行为 
        /// </summary> 
        /// <param name="parameter"></param> 
        public void Execute(object parameter) 
        { 
            if (parameter != null) 
            { MessageBox.Show(parameter.ToString()); } 
            else 
            { 
                MessageBox.Show("未设置CommandParameter"); 
            } 
        } 
    } 
}