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



     

  • 相关阅读:
    sql server 纵横表的转换
    url参数的编码解码Demo
    SqlServer 列的增加和删除
    asp.net下ajax.ajaxMethod使用方法(转)
    js中document.all 的用法
    cookie跨域,跨目录访问及单点登录。
    错误记录:html隐藏域的值存字符串时出错
    .NET下用C#实现邮箱激活功能
    js与C#服务端 json数据交互
    sqlserver数据可空插入报错
  • 原文地址:https://www.cnblogs.com/chenjinshi/p/4284553.html
Copyright © 2011-2022 走看看