using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Tango.Settings; namespace Tango.MachineStudio.Common.Resources { /// /// 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; var settings = SettingsManager.Default.GetOrCreate(); //add current theme MachineStudioTheme wTheme = settings.Theme; #if LITE wTheme = MachineStudioTheme.Dark; #endif if ((wTheme == MachineStudioTheme.Dark && value.LocalPath.Contains("Light")) || (wTheme == MachineStudioTheme.Light && value.LocalPath.Contains("Dark"))) return; 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]); } } } } }