Пример #1
0
        public static IGeneratorComponent Convert(IComponent component)
        {
            IGeneratorComponent Result;

            if (component is IComponentArea AsComponentArea)
            {
                Result = new GeneratorComponentArea(AsComponentArea);
            }
            else if (component is IComponentButton AsComponentButton)
            {
                Result = new GeneratorComponentButton(AsComponentButton);
            }
            else if (component is IComponentCheckBox AsComponentCheckBox)
            {
                Result = new GeneratorComponentCheckBox(AsComponentCheckBox);
            }
            else if (component is IComponentContainer AsComponentContainer)
            {
                Result = new GeneratorComponentContainer(AsComponentContainer);
            }
            else if (component is IComponentContainerList AsComponentContainerList)
            {
                Result = new GeneratorComponentContainerList(AsComponentContainerList);
            }
            else if (component is IComponentEdit AsComponentEdit)
            {
                Result = new GeneratorComponentEdit(AsComponentEdit);
            }
            else if (component is IComponentImage AsComponentImage)
            {
                Result = new GeneratorComponentImage(AsComponentImage);
            }
            else if (component is IComponentIndex AsComponentIndex)
            {
                Result = new GeneratorComponentIndex(AsComponentIndex);
            }
            else if (component is IComponentPasswordEdit AsComponentPasswordEdit)
            {
                Result = new GeneratorComponentPasswordEdit(AsComponentPasswordEdit);
            }
            else if (component is IComponentPopup AsComponentPopup)
            {
                Result = new GeneratorComponentPopup(AsComponentPopup);
            }
            else if (component is IComponentRadioButton AsComponentRadioButton)
            {
                Result = new GeneratorComponentRadioButton(AsComponentRadioButton);
            }
            else if (component is IComponentSelector AsComponentSelector)
            {
                Result = new GeneratorComponentSelector(AsComponentSelector);
            }
            else if (component is IComponentText AsComponentText)
            {
                Result = new GeneratorComponentText(AsComponentText);
            }
            else if (component is IComponentHtml AsComponentHtml)
            {
                Result = new GeneratorComponentHtml(AsComponentHtml);
            }
            else
            {
                throw new InvalidOperationException();
            }

            return(Result);
        }
Пример #2
0
        private void GenerateXaml(IGeneratorDomain domain, string appNamespace, IGeneratorColorTheme colorTheme, StreamWriter xamlWriter)
        {
            xamlWriter.WriteLine($"<Page x:Class=\"{appNamespace}.{XamlName}\"");
            xamlWriter.WriteLine("      xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"");
            xamlWriter.WriteLine("      xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"");
            xamlWriter.WriteLine("      xmlns:n=\"clr-namespace:NetTools\"");
            xamlWriter.WriteLine("      xmlns:p=\"clr-namespace:Presentation\"");
            xamlWriter.WriteLine("      xmlns:conv=\"clr-namespace:Converters\"");
            xamlWriter.WriteLine($"      xmlns:local=\"using:{appNamespace}\"");

            if (!string.IsNullOrEmpty(Tag))
            {
                xamlWriter.WriteLine($"      Tag=\"{Tag}\"");
            }

            xamlWriter.WriteLine("    >");
            xamlWriter.WriteLine("    <Page.Resources>");
            xamlWriter.WriteLine("        <conv:KeyToValueConverter x:Key=\"convKeyToValue\"/>");
            xamlWriter.WriteLine("        <conv:IndexToVisibilityConverter x:Key=\"convIndexToVisibility\"/>");
            xamlWriter.WriteLine("        <conv:IndexToCheckedConverter x:Key=\"convIndexToChecked\"/>");

            foreach (IGeneratorResource Resource in domain.Resources)
            {
                Resource.GenerateResourceLine(xamlWriter);
            }

            int    Indentation = 2;
            string s           = GeneratorLayout.IndentationString(Indentation);

            // Make sure areas used by other areas are first
            List <IGeneratorArea> Areas = new List <IGeneratorArea>();

            foreach (IGeneratorArea Area in domain.Areas)
            {
                if (Area.IsReferencedBy(this.Area))
                {
                    Areas.Add(Area);
                }
            }

            BubbleSort(Areas);

            foreach (IGeneratorArea Area in Areas)
            {
                if (Area.CurrentObject == null)
                {
                    xamlWriter.WriteLine($"{s}<ControlTemplate x:Key=\"{Area.XamlName}\">");
                }
                else
                {
                    xamlWriter.WriteLine($"{s}<DataTemplate x:Key=\"{Area.XamlName}\">");
                }

                IGeneratorLayout Layout = AreaLayouts[Area];
                Area.Generate(Layout, AreaLayouts, domain.Pages, Design, Indentation + 1, this, colorTheme, xamlWriter);

                if (Area.CurrentObject == null)
                {
                    xamlWriter.WriteLine($"{s}</ControlTemplate>");
                }
                else
                {
                    xamlWriter.WriteLine($"{s}</DataTemplate>");
                }
            }

            if (Background != null)
            {
                Background.GenerateResource(xamlWriter, colorTheme);
            }

            xamlWriter.WriteLine("    </Page.Resources>");

            if (IsScrollable)
            {
                string BackgroundColorProperty = $" Color=\"{BackgroundColor}\"";
                colorTheme.WriteXamlLine(xamlWriter, $"    <ScrollViewer>");
                colorTheme.WriteXamlLine(xamlWriter, "        <ScrollViewer.Background>");
                colorTheme.WriteXamlLine(xamlWriter, $"            <SolidColorBrush{BackgroundColorProperty}/>");
                colorTheme.WriteXamlLine(xamlWriter, "        </ScrollViewer.Background>");
                Indentation++;
            }

            s = GeneratorLayout.IndentationString(Indentation - 1);

            string PageHeight = double.IsNaN(Height) ? "" : $" Height=\"{Height}\"";

            xamlWriter.WriteLine($"{s}<Grid PointerPressed=\"OnPointerPressed\"{PageHeight}>");

            if (Background != null)
            {
                Background.Generate(xamlWriter, Indentation, colorTheme);
            }
            GeneratorComponentArea.Generate(Area, "", "", Indentation, colorTheme, xamlWriter, "", Width);

            xamlWriter.WriteLine($"{s}</Grid>");

            if (IsScrollable)
            {
                Indentation--;
                xamlWriter.WriteLine("    </ScrollViewer>");
            }

            xamlWriter.WriteLine("</Page>");
        }