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 == )
{
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() == )
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
C#不同页面之间通信的方法的更多相关文章
- PHP页面之间跳转方法总结
编程中,在页面之间进行跳转是必须的.这里列出了三种办法,供参考. 一.用HTTP头信息 也就是用PHP的HEADER函数.PHP里的HEADER函数的作用就是向浏览器发出由HTTP协议规定的本来应该通 ...
- JS中iframe子页面与父页面之间通信
iframe子页面与父页面通信根据iframe中src属性是同域链接还是跨域链接,通信方式也不同. 一.同域下父子页面的通信 父页面parent.html <html> <head& ...
- C#中页面之间跳转方法比较
一直以来,各种跳转方法混用,浑浑噩噩没有仔细去了解过每个跳转方法的区别 1.<a herf="default.asp"></a> 超链接跳转 2.< ...
- iframe脸面的页面和父页面之间的交互方法
1.iframe父页面修改iframe中的页面的信息 var obj = document.getElementById("iframeId").contentWindow; ...
- jQuery中,子页面与父页面之间的调用方法
在jQuery中, 子页面查找父页面的元素 parent.$("#元素Id") 父页面调用子页面的元素 $("#子页面iframe的Id").contents( ...
- ASP.NET 页面之间传递参数方法
1.通过URL链接地址传递 (1) send.aspx代码 protected void Button1_Click(object sender, EventArgs e) { Request.Red ...
- 页面之间传值的方法asp
原文发布时间为:2008-06-02 -- 来源于本人的百度文章 [由搬家工具导入] asp.net页面间传值 今天学习中要在两个页面中传值,网上搜了一下,asp.net主要用到三个方法,前两个req ...
- JavaScript之iframe页面间通信
[1] iframe父子页面间通信 1.相互调用对方的方法 |> 子级页面调用父级页面 window.parent.父级页面方法(args) |> 父级页面调用子级页面 document. ...
- ASP.NET 弹出对话框和页面之间传递值的经验总结
今天碰到一个弹出对话框(PopUp dialog)的问题, 因该是个傻瓜问题, 但是还是让我研究了半天, 总结了一些前人经验, 拿出来跟大家分享一下! 在ASP.Net中页面之间的传值方法有很多,但是 ...
随机推荐
- 编译代码报出Android library projects cannot be launched错误的解决
Android library projects cannot be launched错误的解决方法: 右键工程根目录->properties 左侧选择->android
- iOS - UI - UIStepper
7.UIStepper //计数器控件 固定宽高 UIStepper * stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 10 ...
- Shuffle an Array
class Solution { private: vector<int> arr, idx; public: Solution(vector<int> nums) { sra ...
- IT技术方案最佳实践方案的收集
一.图片鉴别服务 1. 阿里云,腾讯云等公开的服务. 2. 图谱科技提供的API 二. 网络直播服务器 1. SRS2 开源服务器 (https://github.com/ossrs/srs/wiki ...
- 【转】学习JAVA的步骤
好东西大家分享: JAVA学习的一些重点 . Java语言基础 谈到Java语言基础学习的书籍,大家肯定会推荐Bruce Eckel的<Thinking in Java>.它是一本写的 ...
- Wordpress 运行缓慢的解决方法
原因为wordpress 3.8之后采用google字体所致. 修改 functions.php //禁用Open Sans class Disable_Google_Fonts { pub ...
- java实现Composite(组合)模式
组合模式涉及的是一组对象,其中一些对象可能含有其他对象,这些对象也可以含有对象,因此,有些对象代表的是对象群组. Composite模式的设计意图在于:让所有的用户能够用统一的接口处理单个对象以及对象 ...
- arcsde service(esri_sde)服务启动后又停止
由于最近几天我们公司换了新办公楼,各种服务器得重新配置.当我试图直接将arcsde Service的服务器IP改为现在的地址,就报上面如题的错误. SQL服务器是好的,不用管它,只要确保它是开启的.只 ...
- Part 8 Coalesce function in sql server
- Javascript 日期时间超强正则表达式
var reg = /^([0-9]{4})-((?:0[1-9]|[1-9]|1[1-2]))-((?:(?:0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1]))$|^([0-9 ...