I need to use a resource dictionary located in my local machine. My WPF application will add/remove items dynamically to that dictionary using Add() or Remove() methods. Once done I need to save the updated resource dictionary again to the disk.
I don't find a direct way for this. Is there anything like ResurceDictionary.Save()?
You can use XamlWriter class.
Here's a piece of code that writes button's template to a file:
// 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With