Пример #1
0
        public int Convert(
            [ArgumentParam(Aliases = "i", Desc = "dir to the SVGs", LongDesc = "specify folder of the graphic files to process")]
            string inputdir,
            [ArgumentParam(DefaultValue = null, ExplicitNeeded = false, LongDesc = "folder for the xaml-Output, optional, default: folder of svgs")]
            string outputdir = null,
            [ArgumentParam(DefaultValue = null, ExplicitNeeded = false, LongDesc = "output path format for xaml-Output, optional, default: {0}.xaml")]
            string outputpath = null
            )
        {
            Console.WriteLine("Converting SVG to XAML...");

            XamlWriteOptions xamlWriteOptions = new XamlWriteOptions()
            {
                IncludeXmlDeclaration = true,
                IncludeNamespaces     = true,
            };

            foreach (string filePath in Directory.GetFiles(inputdir, "*.svg", SearchOption.AllDirectories))
            {
                string filePathWithoutExtension = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath));
                string outPath = String.Format(outputpath ?? "{0}.xaml", filePathWithoutExtension);
                string xaml    = ConverterLogic.SvgFileToXaml(filePath, ResultMode.DrawingImage, xamlWriteOptions: xamlWriteOptions);
                File.WriteAllText(outPath, xaml);
                Console.WriteLine($"xaml written to: {outPath}");
            }

            return(0);
        }
Пример #2
0
        public static string SvgObjectToXaml(object obj, bool includeRuntime, XamlWriteOptions options)
        {
            string xamlUntidy = WpfObjToXaml(obj, includeRuntime);

            XDocument doc = XDocument.Parse(xamlUntidy);

            BeautifyDrawingElement(doc.Root, options.Name);
            string xaml = doc.ToString();

            if (options.IncludeXmlDeclaration)
            {
                XDeclaration declaration = new XDeclaration("1.0", "UTF-8", null);
                xaml = declaration.ToString() + Environment.NewLine + xaml;
            }

            if (!options.IncludeNamespaces)
            {
                xaml = RemoveNamespaceDeclarations(xaml);
            }

            return(xaml);
        }
Пример #3
0
        public static string SvgFileToXaml(string filepath, ResultMode resultMode, ResKeyInfo resKeyInfo = null, WpfDrawingSettings wpfDrawingSettings = null, XamlWriteOptions xamlWriteOptions = null, ResourceDictionary resources = null)
        {
            string name;
            var    obj = ConvertSvgToObject(filepath, resultMode, wpfDrawingSettings, out name, resKeyInfo ?? new ResKeyInfo(), resources);

            return(SvgObjectToXaml(obj, wpfDrawingSettings != null && wpfDrawingSettings.IncludeRuntime, xamlWriteOptions ?? new XamlWriteOptions()
            {
                Name = name
            }));
        }