我在我的WPF项目中使用了AvalonEdit控件,并将其与XML语法高亮显示一起使用。我只是把它作为XML编辑器使用(不需要侧面的树视图或任何东西)。我想要的是:
removed/updated/deleted.
的基础上自动遵从时获取通知。
我看到新的AvalonEdit有一个ICSharpCode.AvalonEdit.Xml名称,但我不知道如何使用它来满足自己的需要。有什么建议吗?
发布于 2012-01-06 10:55:49
我知道如何完成第一部分(假设您可以使用LINQ (即有.NET 3.5或更高版本),这只是一个使用一些XLINQ并连接两个更改/更改的事件的问题,如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Collections.ObjectModel;
using System.Reactive.Linq;
namespace ConsoleApplication1
{
class Program
{
public static XDocument doc;
static void Main(string[] args)
{
doc = XDocument.Parse("<books><book>Gone with the wind</book></books>");
doc.Changed += Doc_Changed;
doc.Changing += Doc_Changing;
PrintResults();
XElement newElement = new XElement("book", "Treasure Island");
doc.Elements().First().Add(newElement);
newElement.Remove(); //remove this noe from parent
Console.ReadLine();
}
static void Doc_Changing(object sender, XObjectChangeEventArgs e)
{
PrintChangeResults(e);
}
static void Doc_Changed(object sender, XObjectChangeEventArgs e)
{
PrintChangeResults(e);
}
public static void PrintChangeResults(XObjectChangeEventArgs e)
{
Console.WriteLine(string.Format("Change was {0}, Document now has {1} elements",
e.ObjectChange, doc.Elements().First().Elements().Count()));
}
public static void PrintResults()
{
Console.WriteLine(string.Format("Document now has {0} elements",
doc.Elements().First().Elements().Count()));
}
}
},这将产生类似于以下输出的结果
文档现在有1个元素更改被添加,文档现在有1个元素更改被添加,文档现在有2个元素更改被删除,文档现在有2个元素更改被删除,文档现在有1个元素
这样你就可以得到1/2的方式了(如果你能利用LINQ)
https://stackoverflow.com/questions/8267577
复制相似问题