• 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



     

  • 相关阅读:
    git命令-切换分支
    Git SSH Key 生成步骤
    12个非常有用的JavaScript技巧
    project 2013 删除资源
    project 2013 工时完成百分比不会自动更新填充
    project 2013 显示标题
    project 2013 任务显示编号
    project 2013 设置工期为1个工作日,但开始时间与结束时间不是同一天
    ecplise properties文件 中文转码
    Jeesite 代码生成
  • 原文地址:https://www.cnblogs.com/chenjinshi/p/4284553.html
Copyright © 2020-2023  润新知