zoukankan      html  css  js  c++  java
  • Silverlight Command的运用

    1:写一个类继承ICommand接口

    public class MyCommand : ICommand
        {
    
            private readonly Action<object> executeAction;
            private readonly Func<object, bool> canExecuteAction;
            public event EventHandler CanExecuteChanged;
            public MyCommand(Action<object> executeAction)
                : this(executeAction, null)
            {
            }
            public MyCommand(Action<object> executeAction,
                Func<object, bool> canExecuteAction)
            {
                this.executeAction = executeAction;
                this.canExecuteAction = canExecuteAction;
            }
            public bool CanExecute(object parameter)
            {
                if (canExecuteAction != null)
                {
                    return canExecuteAction((object)parameter);
                }
                return true;
            }
            public void Execute(object parameter)
            {
                if (CanExecute(parameter))
                {
                    executeAction((object)parameter);
                }
            }
    
        }

    2:在ViewMode中定义一个Comand 返回一个自定义Command实例,传入方法

      public class MainPageViewMode
        {
            public ICommand ShowHello { get { return new MyCommand(showhello); } }
    
    
            private void showhello(object param)
            {
                MessageBox.Show("Hello!");
            }
    
        }

    3:前台运用

     <Button x:Name="addxap" Content="CommandTest" Command="{Binding ShowHello}" />
    

    这样,点击按钮的时候就会执行ViewMode中的方法了。

  • 相关阅读:
    linux之iptable案例
    nginx常用命令参数
    laravel中的多对多关系详解
    MySql计算时间差函数
    总结下Mysql分表分库的策略及应用
    swoole扩展实现真正的数据库连接池
    linux常用命令整理
    innodb mvcc实现机制
    mysqlslap 压力测试使用总结
    mysql索引总结
  • 原文地址:https://www.cnblogs.com/Rmeo/p/3089446.html
Copyright © 2011-2022 走看看