• 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



     

  • 相关阅读:
    NSURLSessionDataDelegate 文件下载
    NSURLConnection 大文件下载
    全屏滑动
    qq粒子效果
    iOS 技巧
    iOS 15 新特性适配
    iOS 字符串转json 字符串转数组
    iOS 微信分享显示未验证应用2
    iOS 微信分享显示未验证应用1
    iOS 隐藏系统音量提示框
  • 原文地址:https://www.cnblogs.com/chenjinshi/p/4284553.html
Copyright © 2020-2023  润新知