[英]Inter process communication for transferring tree structure
我想将一棵 UI 对象树从进程 A 传输到 B。即进程 B 想知道进程 A 中窗口的布局。我发现下面的链接几乎是我需要的,但此链接中的方法只能很好地传输对象- 定义的结构。 关联
虽然我要转移树结构:我事先不知道布局。
谁能给我一些提示? 多谢!
我认为你的项目看起来像下面的代码。 您可能需要自定义序列化程序或从您的进程中创建一个树来填充窗口和控件。 从你的描述中不确定什么是最好的处理方式。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Process process = new Process();
XDocument doc = new XDocument("root");
XElement xProcess = SerializeToXml<Process>.Serialize(process);
doc.Add(xProcess);
}
}
public class SerializeToXml <T>
{
public static XElement Serialize(T data)
{
StringWriter writer = new StringWriter();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter xWriter = XmlWriter.Create(writer, settings);
XmlSerializer serializer = new XmlSerializer(data.GetType());
serializer.Serialize(xWriter, data);
XmlReader reader = XmlReader.Create(xWriter.ToString());
writer.Close();
return (XElement)XElement.ReadFrom(reader);
}
}
public class Process
{
public List<Window> windows { get; set; }
}
public class Window
{
public List<Control> controls { get; set; }
}
public class Control
{
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.