zoukankan      html  css  js  c++  java
  • C#不同页面之间通信的方法

    以前做项目的时候经常头疼两个页面之间的交互(汗),这几天看的MVVM项目,忽然感觉好简单的!我自己写了个简单的demo

    可以简单实现2个页面之间的交互,新人第一次发博客,不喜勿喷

    代码很简单,注释我就不打了

    下面是代码:

     public static class PublicAction
        {
            static List<ActionParas> actionList = new List<ActionParas>();
    
            public static void Regist(string name, Action<object> action)
            {
                var num = actionList.Where(i => i.Name == name).Count();
                if (actionList.Count == 0)
                {
                    var hh = new ActionParas();
                    hh.ActionList.Add(action);
                    hh.Name = name;
                    actionList.Add(hh);
                }
                else
                {
                    var item = actionList.Where(i => i.Name == name).First();
                    if (item.ActionList.Where(i => i == action).Count() == 0)
                        item.ActionList.Add(action);
                }
            }
    
            public static void Send(string name, object obj)
            {
                var items = actionList.Where(i => i.Name == name).First();
                foreach (var item in items.ActionList)
                {
                    item.Invoke(obj);
                }
            }
    
            public static void Remove(string name)
            {
                var item = actionList.Where(i => i.Name == name).First();
                actionList.Remove(item);
            }
    
        }
      public class ActionParas
        {
            private string _name;
    
            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }
            private List<Action<object>> actionList;
    
            public List<Action<object>> ActionList
            {
                get { if (actionList == null) { actionList = new List<Action<object>>(); } return actionList; }
                set { actionList = value; }
            }
        }
    
    
    
    
    

    代码在

    http://ad9ayimfpb.l75.yunpan.cn/lk/cK4uHDzVNHBvW

    提取码c10d



     

  • 相关阅读:
    msp430时钟小结
    JDBC第一天连接池案例
    maltab几个常见的问题
    qt 获取天气的接口
    Qt Style Sheets制作UI特效
    qt 在指定区域添加图片
    qt 设置背景图片
    linux下mysql数据库的学习
    qt文本编辑器
    C++小游戏:扑克牌21点
  • 原文地址:https://www.cnblogs.com/chenjinshi/p/4284553.html
Copyright © 2011-2022 走看看