【发布时间】:2012-03-13 15:37:10
【问题描述】:
我正在尝试对许多 XAML 文件进行一些批量更改,并且我尝试通过使用 linq 的 XDocument 对其进行编辑来做到这一点。这工作正常,我可以添加新元素,但是我遇到了缩进问题:
文档加载了“PreserveWhitseSpace”,因为我需要保持格式(因为 SVN):
_xamlDocument = XDocument.Load(new StringReader(newContent), LoadOptions.PreserveWhitespace);
然后我添加一些元素,完成后我使用以下命令保存文件:
_xamlDocument.Save(stringWriter, SaveOptions.None);
新添加的元素没有很好地缩进,看起来不太好(抱歉这里的格式,但你会看到 /n 字符串):
<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<UserControl x:Class=\"Sonova.Chinook.UserInterface.Common.SimpleProgressView\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" Content=\"{Binding}\">\r\n <UserControl.Resources>\r\n \r\n <ResourceDictionary><ResourceDictionary.MergedDictionaries><ResourceDictionary Source=\"{ThemeDictionary AssemblyName=Cocoon.UserInterface}\" /><ResourceDictionary Source=\"/Cocoon.UserInterface;component/VisualResources/Controls/ContentControl.xaml\" /></ResourceDictionary.MergedDictionaries></ResourceDictionary></UserControl.Resources>\r\n <UserControl.Style>\r\n <StaticResource ResourceKey=\"SimpleProgressStyle\" />\r\n </UserControl.Style>\r\n</UserControl>
上面的 Xml 显示没有换行符或空格,例如以下元素:
<ResourceDictionary Source=\"{ThemeDictionary AssemblyName=Cocoon.UserInterface}\" /><ResourceDictionary
我已经尝试将禁用格式设置为保存选项,但似乎没有一个会导致所需的结果。
有什么想法吗? 最好的问候
【问题讨论】:
-
我找到了这个附加信息,但是我正在寻找一种方法来保留空白,并很好地格式化新元素bytes.com/topic/net/answers/…
标签: .net linq xaml indentation linq-to-xml