2012-05-03 7 views
2

ローカルマシンにあるリソース辞書を使用する必要があります。私のWPFアプリケーションは、Add()メソッドまたはRemove()メソッドを使用して項目を動的に追加/削除します。完了したら、更新されたリソース辞書をディスクに再度保存する必要があります。プログラムでリソース辞書をディスクに保存する

私はこれに直接的な方法はありません。 ResurceDictionary.Save()のようなものはありますか?

答えて

2

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); 
+0

のStringBuilderで何までですか? – vidstige

+0

ああ、それを逃した – EvAlex

0
ResourceDictionary dic = Application.Current.Resources; 

StreamWriter writer = new StreamWriter("Themes\\NewOne.xaml"); 
XamlWriter.Save(dic, writer); 
writer.Close(); 
関連する問題