zoukankan      html  css  js  c++  java
  • C# WPF 路由命令

    下面是一个简单的投影转换小工具

    通过路由命令实现在所有参数都正确输入的情况下,"确定" 按钮可用

    // 定义与绑定路由命令 OkButton对象就是确定按钮
    RoutedCommand OkButtonCommand = new RoutedCommand("ReprojectRaster", typeof(MainWindow));
    OkButton.Command = OkButtonCommand;
    CommandBinding commandBinding = new CommandBinding();
    commandBinding.Command = OkButtonCommand;
    commandBinding.CanExecute += OkButtonCommandBinding_CanExecute;
    commandBinding.Executed += OkButtonCommandBinding_Executed; ;
    this.CommandBindings.Add(commandBinding);
    
    // 监听OkButton状态
    private void OkButtonCommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
    {
        // 添加一系列条件代码
        if ........
        else if ........
     
        e.CanExecute = false; // OkButton显示为不可用转态
        e.CanExecute = true; // OkButton显示为可用转态
    }
    
    // 执行OkButton点击的功能
    private void OkButtonCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
    {
       // 一系列数据处理代码
       ....
       e.Handled = true;
    }
    
  • 相关阅读:
    Python列表及元组操作
    Python内建函数
    Python字符串相关
    检测浏览器是否安装FLASH插件
    瀑布流源码
    addEventListener 简析
    半角占一个字符,全角占两个字符
    替换class名
    正则表达式 验证是否全是空格
    图片旋转
  • 原文地址:https://www.cnblogs.com/lqqgis/p/12649931.html
Copyright © 2011-2022 走看看