Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically save Resource Dictionary to Disk

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()?

like image 468
WPF Lover Avatar asked May 25 '26 16:05

WPF Lover


1 Answers

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);
like image 121
EvAlex Avatar answered May 28 '26 06:05

EvAlex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!