Esempio n. 1
0
        internal static void UpdateTheme(ResourceDictionary resourceDictionary, Theme theme)
        {
            ResourceDictionary brushResourceDictionary = resourceDictionary.FindDictionary(BrushDictionaryUri.ToString());

            if (brushResourceDictionary != null)
            {
                if (theme == Theme.Dark)
                {
                    brushResourceDictionary.ReplaceDictionary(LightColorDictionaryUri, DarkColorDictionaryUri);
                }
                else
                {
                    brushResourceDictionary.ReplaceDictionary(DarkColorDictionaryUri, LightColorDictionaryUri);
                }
            }
            else
            {
                if (theme == Theme.Dark)
                {
                    resourceDictionary.MergedDictionaries.Add(
                        new ResourceDictionary()
                    {
                        Source = DarkColorDictionaryUri
                    });
                }
                else
                {
                    resourceDictionary.MergedDictionaries.Add(
                        new ResourceDictionary()
                    {
                        Source = LightColorDictionaryUri
                    });
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The contains.
        /// </summary>
        /// <param name="resourceDictionary">
        /// The resource dictionary.
        public static bool ContainsDictionary(this ResourceDictionary resourceDictionary, ResourceDictionary resource)
        {
            if (resource.Source == null)
            {
                return(false);
            }

            var foundDictionary = resourceDictionary.FindDictionary(resource.Source);

            return(foundDictionary != null);
        }
Esempio n. 3
0
        /// <summary>
        /// Determines if the specified resource dictionary (source) exists anywhere in the
        /// resource dictionary recursively.
        /// </summary>
        public static bool ContainsDictionary(this ResourceDictionary resourceDictionary, Uri source)
        {
            if (string.IsNullOrEmpty(source.LocalPath))
            {
                return(false);
            }

            var foundDictionary = resourceDictionary.FindDictionary(source);

            return(foundDictionary != null);
        }
        /// <summary>
        /// Determines if the specified resource dictionary (source) exists anywhere in the
        /// resource dictionary recursively.
        /// </summary>
        /// <param name="resourceDictionary">
        /// The resource dictionary.
        /// </param>
        /// <param name="source">
        /// The url of the resource dictionary to find.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool ContainsDictionary(this ResourceDictionary resourceDictionary, string source)
        {
            if (resourceDictionary == null || string.IsNullOrEmpty(source))
            {
                return(false);
            }

            var foundDictionary = resourceDictionary.FindDictionary(source);

            return(foundDictionary != null);
        }
Esempio n. 5
0
 private static void UpdateColor(ResourceDictionary resourceDictionary, string key, Color color)
 {
     if (color != null && !((color.A == 0) && (color.R == 0) && (color.G == 0) && (color.B == 0)))
     {
         ResourceDictionary brushResourceDictionary = resourceDictionary.FindDictionary(BrushDictionaryUri.ToString());
         if (brushResourceDictionary != null)
         {
             ResourceDictionary oldColorResourceDictionary = brushResourceDictionary.FindDictionary(ColorDictionaryUri.ToString());
             ResourceDictionary colorResourceDictionary    = new ResourceDictionary()
             {
                 Source = ColorDictionaryUri
             };
             colorResourceDictionary["AccentColor"]   = oldColorResourceDictionary["AccentColor"];
             colorResourceDictionary["ContrastColor"] = oldColorResourceDictionary["ContrastColor"];
             colorResourceDictionary["SemitransparentContrastColor"] = oldColorResourceDictionary["SemitransparentContrastColor"];
             colorResourceDictionary[key] = color;
             brushResourceDictionary.ReplaceDictionary(ColorDictionaryUri, colorResourceDictionary);
         }
     }
 }