我需要使用位于本地计算机中的资源字典。我的WPF应用程序将使用Add()或Remove()方法动态地向该字典添加/删除条目。完成后,我需要再次将更新后的资源字典保存到磁盘。
我找不到一个直接的方法来解决这个问题。有没有像ResurceDictionary.Save()这样的东西?
发布于 2012-05-03 18:48:56
您可以使用XamlWriter类。
这是一段将按钮的模板写到文件中的代码:
// Get the template.
ControlTemplate template = button.Template;
// Get the XAML for the template.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create(@"c:\template.xaml", settings);
XamlWriter.Save(template, writer);发布于 2013-01-05 23:58:48
ResourceDictionary dic = Application.Current.Resources;
StreamWriter writer = new StreamWriter("Themes\\NewOne.xaml");
XamlWriter.Save(dic, writer);
writer.Close();https://stackoverflow.com/questions/10428042
复制相似问题