Microsoft.Silverlight.Toolkit.Build.Tasks.DefaultStyle.LowerNamespace C# (CSharp) Method

LowerNamespace() private method

Lower a namespace from the root ResourceDictionary to its child resources.
private LowerNamespace ( string prefix ) : void
prefix string Prefix of the namespace to lower.
return void
        private void LowerNamespace(string prefix)
        {
            // Get the value of the namespace
            string @namespace;
            if (!Namespaces.TryGetValue(prefix, out @namespace))
            {
                return;
            }

            // Push the value into each resource
            foreach (KeyValuePair<string, XElement> resource in Resources)
            {
                // Don't push the value down if it was overridden locally or if
                // it's the default namespace (as it will be lowered
                // automatically)
                if (((from e in resource.Value.Attributes()
                      where e.Name.LocalName == prefix
                      select e).Count() == 0) &&
                    !string.IsNullOrEmpty(prefix))
                {
                    resource.Value.Add(new XAttribute(XName.Get(prefix, XNamespace.Xmlns.NamespaceName), @namespace));
                }
            }
        }

Usage Example

        /// <summary>
        /// Merge with another DefaultStyle.
        /// </summary>
        /// <param name="other">Other DefaultStyle to merge.</param>
        private void Merge(DefaultStyle other)
        {
            // Merge or lower namespaces
            foreach (KeyValuePair <string, string> ns in other.Namespaces)
            {
                string value = null;
                if (!Namespaces.TryGetValue(ns.Key, out value))
                {
                    Namespaces.Add(ns.Key, ns.Value);
                }
                else if (value != ns.Value)
                {
                    other.LowerNamespace(ns.Key);
                }
            }

            // Merge the resources
            foreach (KeyValuePair <string, XElement> resource in other.Resources)
            {
                if (Resources.ContainsKey(resource.Key))
                {
                    throw new InvalidOperationException(string.Format(
                                                            CultureInfo.InvariantCulture,
                                                            "Resource \"{0}\" is used by both {1} and {2}!",
                                                            resource.Key,
                                                            MergeHistory[resource.Key],
                                                            other.DefaultStylePath));
                }
                Resources[resource.Key]    = resource.Value;
                MergeHistory[resource.Key] = other.DefaultStylePath;
            }
        }
All Usage Examples Of Microsoft.Silverlight.Toolkit.Build.Tasks.DefaultStyle::LowerNamespace