zoukankan      html  css  js  c++  java
  • 【Prism】MEF版Commanding

    引言

         接下来的是Commanding Demo的改造.

    DelegateCommand

       WPF本身提供了一个RoutedCommand,然而没什么卵用.在Prism框架中提供了个更人性化的ICommand的实现--DelegateCommand,如下

    public class ArticleViewModel : NotificationObject
    {
        private readonly ICommand showArticleListCommand;
    
        public ArticleViewModel(INewsFeedService newsFeedService,
                                IRegionManager regionManager,
                                IEventAggregator eventAggregator)
        {
            this.showArticleListCommand = new DelegateCommand(this.ShowArticleList);
        }
    
        public ICommand ShowArticleListCommand 
        {
            get { return this.showArticleListCommand; } 
        }
    }

    CompositeCommand

        CompositeCommand是Prism提供的一个组合式命令实现.它可以在子命令都可用的情况下同时执行多个子命令.应用情况不是很多,但是可以了解一下.如下

    public class MyViewModel : NotificationObject
    {
        private readonly CompositeCommand saveAllCommand;
    
        public ArticleViewModel(INewsFeedService newsFeedService,
                                IRegionManager regionManager,
                                IEventAggregator eventAggregator)
        {
            this.saveAllCommand = new CompositeCommand();
            this.saveAllCommand.RegisterCommand(new SaveProductsCommand());
            this.saveAllCommand.RegisterCommand(new SaveOrdersCommand());
        }
    
        public ICommand SaveAllCommand
        {
            get { return this.saveAllCommand; }
        }
    }

    示例源码

           http://pan.baidu.com/s/1sjuWkod

    小结

         更多的Commandi用法可以在官方文档Prism 4.0的Chapter 9中查阅.

  • 相关阅读:
    108.Convert Sorted Array to Binary Search Tree
    111.Minimum Depth of Binary Tree
    118.Pascal's Triangle
    122.Best Time to Buy and Sell Stock II
    35.搜索插入位置
    OSI参考模型
    虚拟机访问tomcat
    linux输入ifconfig找不到IP的解决办法
    分层协议、协议、接口、服务
    Spring Boot项目的创建
  • 原文地址:https://www.cnblogs.com/caizl/p/4676629.html
Copyright © 2011-2022 走看看