示例#1
0
        private void genCodeBtn_Click(object sender, RoutedEventArgs e)
        {
            XmlDocument    xml_document = new XmlDocument();
            XmlDeclaration xmldecl      = xml_document.CreateXmlDeclaration("1.0", "UTF-8", "yes");

            if (vm.CodeGenProperties.DataEntryStyle == CodeGenProperties.DataEntry.Form)
            {
                xml_document.LoadXml(GenerateDataForm.Generate(vm.selectedBlock, vm.CodeGenProperties));
            }
            else if (vm.CodeGenProperties.DataEntryStyle == CodeGenProperties.DataEntry.Grid)
            {
                xml_document.LoadXml(GenerateDataGrid.Generate(vm.selectedBlock, vm.CodeGenProperties));
            }

            XmlElement root = xml_document.DocumentElement;

            xml_document.InsertBefore(xmldecl, root);

            StringWriter  string_writer   = new StringWriter();
            XmlTextWriter xml_text_writer = new XmlTextWriter(string_writer);

            xml_text_writer.Formatting = Formatting.Indented;
            xml_document.WriteTo(xml_text_writer);

            documentViewer.XmlDocument = xml_document;
            vm.GeneratedXAML           = string_writer.ToString();
            vm.GeneratedVMCode         = GenerateViewModel.Generate(vm.selectedBlock, vm.CodeGenProperties);
            vm.GeneratedCode           = GenerateCodeBehind.Generate(vm.selectedBlock, vm.CodeGenProperties);

            vm.GeneratedCode += "\n" + vm.GeneratedVMCode;

            xml_text_writer.Close();
            string_writer.Close();
        }