From 080f1697e97e13461ec6df4d31c8924d01257a1b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 9 Apr 2019 01:47:48 +0300 Subject: MERGE --- .../Controls/SharedResourceDictionary.cs | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.IDE/Controls/SharedResourceDictionary.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.IDE/Controls/SharedResourceDictionary.cs') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.IDE/Controls/SharedResourceDictionary.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.IDE/Controls/SharedResourceDictionary.cs new file mode 100644 index 000000000..a163355c4 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.IDE/Controls/SharedResourceDictionary.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; + +namespace Tango.Scripting.IDE.Controls +{ + + /// + /// The shared resource dictionary is a specialized resource dictionary + /// that loads it content only once. If a second instance with the same source + /// is created, it only merges the resources from the cache. + /// + public class SharedResourceDictionary : ResourceDictionary + { + /// + /// Internal cache of loaded dictionaries + /// + public static Dictionary _sharedDictionaries = + new Dictionary(); + + /// + /// Local member of the source uri + /// + private Uri _sourceUri; + + /// + /// Gets or sets the uniform resource identifier (URI) to load resources from. + /// + public new Uri Source + { + get { return _sourceUri; } + set + { + _sourceUri = value; + + if (!_sharedDictionaries.ContainsKey(value)) + { + // If the dictionary is not yet loaded, load it by setting + // the source of the base class + base.Source = value; + + // add it to the cache + _sharedDictionaries.Add(value, this); + } + else + { + // If the dictionary is already loaded, get it from the cache + MergedDictionaries.Add(_sharedDictionaries[value]); + } + } + } + } +} \ No newline at end of file -- cgit v1.3.1