Ejemplo n.º 1
0
        private static ResourceDictionary ExtractResources(DrawingGroup dg, ResourceDictionary resources = null)
        {
            if (resources == null)
            {
                resources = new ResourceDictionary();
            }

            foreach (Drawing drawing in dg.Children)
            {
                drawing.SetValue(SvgObject.IdProperty, DependencyProperty.UnsetValue);
                drawing.SetValue(SvgLink.KeyProperty, DependencyProperty.UnsetValue);

                GeometryDrawing geometryDrawing = drawing as GeometryDrawing;
                if (geometryDrawing != null)
                {
                    string className = SvgObject.GetClass(drawing);
                    if (!string.IsNullOrEmpty(className))
                    {
                        string resourceName = ClassNameToResourceName(className);
                        if (!resources.Contains(resourceName))
                        {
                            resources.Add(resourceName, geometryDrawing.Brush);
                        }
                    }
                }

                DrawingGroup childGroup = drawing as DrawingGroup;
                if (childGroup != null)
                {
                    ExtractResources(childGroup, resources);
                }
            }

            return(resources);
        }