Exemplo n.º 1
0
        internal static Uri GenerateFallbackUri(ResourceDictionary dictionary, string resourceName)
        {
            for (int i = 0; i < _themeDictionaryInfos.Count; i++)
            {
                ThemeDictionaryInfo info = _themeDictionaryInfos[i];

                if (!info.DictionaryReference.IsAlive)
                {
                    // Remove from list
                    _themeDictionaryInfos.RemoveAt(i);
                    i--;
                    continue;
                }
                if ((ResourceDictionary)info.DictionaryReference.Target == dictionary)
                {
                    string themeName = resourceName.Split('/')[1];
                    return(GenerateUri(info.AssemblyName, resourceName, themeName));
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        private static void Register(ResourceDictionary dictionary, string assemblyName)
        {
            Debug.Assert(dictionary != null, "dictionary should not be null");
            Debug.Assert(assemblyName != null, "assemblyName should not be null");

            if (_themeDictionaryInfos == null)
            {
                _themeDictionaryInfos = new List <ThemeDictionaryInfo>();
            }
            ThemeDictionaryInfo info;

            for (int i = 0; i < _themeDictionaryInfos.Count; i++)
            {
                info = _themeDictionaryInfos[i];

                if (!info.DictionaryReference.IsAlive)
                {
                    // Remove from list
                    _themeDictionaryInfos.RemoveAt(i);
                    i--;
                    continue;
                }

                if (info.DictionaryReference.Target == dictionary)
                {
                    info.AssemblyName = assemblyName;
                    return;
                }
            }

            // Not present, add to list
            info = new ThemeDictionaryInfo();
            info.DictionaryReference = new WeakReference(dictionary);
            info.AssemblyName        = assemblyName;

            _themeDictionaryInfos.Add(info);
        }
Exemplo n.º 3
0
        internal static void OnThemeChanged()
        {
            // Update all resource dictionaries

            if (_themeDictionaryInfos != null)
            {
                for (int i = 0; i < _themeDictionaryInfos.Count; i++)
                {
                    ThemeDictionaryInfo info = _themeDictionaryInfos[i];

                    if (!info.DictionaryReference.IsAlive)
                    {
                        // Remove from list
                        _themeDictionaryInfos.RemoveAt(i);
                        i--;
                        continue;
                    }

                    // Provide the new dictionary URI
                    ResourceDictionary dictionary = (ResourceDictionary)info.DictionaryReference.Target;
                    dictionary.Source = GenerateUri(info.AssemblyName, SystemResources.ResourceDictionaries.ThemedResourceName, MS.Win32.UxThemeWrapper.ThemeName);
                }
            }
        }
Exemplo n.º 4
0
        private static void Register(ResourceDictionary dictionary, string assemblyName)
        {
            Debug.Assert(dictionary != null, "dictionary should not be null");
            Debug.Assert(assemblyName != null, "assemblyName should not be null");

            if (_themeDictionaryInfos == null)
            {
                _themeDictionaryInfos = new List<ThemeDictionaryInfo>();
            }
            ThemeDictionaryInfo info;
            
            for (int i = 0; i < _themeDictionaryInfos.Count; i++)
            {
                info = _themeDictionaryInfos[i];

                if (!info.DictionaryReference.IsAlive)
                {
                    // Remove from list
                    _themeDictionaryInfos.RemoveAt(i);
                    i--;
                    continue;
                }

                if (info.DictionaryReference.Target == dictionary)
                {
                    info.AssemblyName = assemblyName;
                    return;
                }
            }

            // Not present, add to list
            info = new ThemeDictionaryInfo();
            info.DictionaryReference = new WeakReference(dictionary);
            info.AssemblyName = assemblyName;

            _themeDictionaryInfos.Add(info);
            
        }