Composite UI 中发布/订阅如何使用?

zhxfzhxf1 2006-11-16 10:05:24
我想使用发布/订阅实现系统间(同一进程内)不同窗体之间的通信,但发现它不能正常工作。
之后,我做了一个简单的测试程序:
创建一个 windows application 项目,
在系统自动创建的Form1(类)上添加CompositeUI中事件代理的引用
标记发布、订阅。
Form1的代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeUI.EventBroker;
using Microsoft.Practices.CompositeUI.Utility;

namespace PS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
OnTextChanged(tbPub.Text);
}
[EventSubscription("topic://EventBrokerQuickStart/TextChanged", Thread = ThreadOption.UserInterface)]
public void OnSensingTextChanged(object sender, DataEventArgs<string> e)
{
tbSub.Text = "sssss" + e.Data;
}

[EventPublication("topic://EventBrokerQuickStart/TextChanged", PublicationScope.Global)]
public event EventHandler<DataEventArgs<string>> TextChangedEvent;
private void OnTextChanged(string strText)
{
if (TextChangedEvent != null)
{
TextChangedEvent(this, new DataEventArgs<string>(strText));
}
}
}
}


在调试时,发现TextChangedEvent始终为null。
而MS 或者其他人提供的例子中对应物则 不是 null。
不知道,使用发布/订阅还需要有什么条件。


请各位高手赐教。
...全文
335 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigrongshu 2006-11-17
  • 打赏
  • 举报
回复
发布和订阅只能在标记为[SmartPart],或者继承自WorkItem, Controller的类
3种情况下有效

一般的Form或者UserControl不行
zhxfzhxf1 2006-11-16
  • 打赏
  • 举报
回复
自己顶一下

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧