I want to transfer a tree of UI objects from process A to B. ie Process B want to know the layout of windows in process A. I found below link nearly what I need, but the method in this link can only transfer objects with well-defined structure. link
While I am going to transfer tree structure: I do not know the layout beforehand.
Can anyone give me some hints? thanks a lot!
I think you project would look like the code below. You may need a custom serializer or to create a tree from your process that fills in the windows and controls. Not sure from you description what is the best way of proceeding.
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
{
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.