예제 #1
0
        public FormTemplateModel(GenerateFormModel generateFormModel)
        {
            if (generateFormModel == null)
            {
                throw new ArgumentNullException(nameof(generateFormModel));
            }
            _generateFormModel = generateFormModel;
            this.RootObject    = generateFormModel.RootObject;
            this.FormComponentModelCollection = GetFormComponentModelCollection();
            this.BorderHelper       = new BorderHelper(generateFormModel.ProjectType);
            this.GridHelper         = new GridHelper();
            this.LabelHelper        = new LabelHelper(generateFormModel.ProjectType);
            this.ScrollViewerHelper = new ScrollViewerHelper(generateFormModel.ProjectType);
            this.StackPanelHelper   = new StackPanelHelper(generateFormModel.ProjectType);
            this.TextBlockHelper    = new TextBlockHelper(generateFormModel.ProjectType);
            this.TableViewHelper    = new TableViewHelper();
            this.TableRootHelper    = new TableRootHelper();
            this.TableSectionHelper = new TableSectionHelper();
            this.ViewCellHelper     = new ViewCellHelper();

            SetRootGridRows();
            SetRootGridColumns();
            MakeRootControl();
            InitializeParentControlWithControlsIncludedOnSameRow();
        }
        protected FormComponentModelBase(GenerateFormModel generateFormModel, PropertyInformationViewModel viewModel)
        {
            if (generateFormModel == null)
            {
                throw new ArgumentNullException(nameof(generateFormModel));
            }
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            this.ViewModel = viewModel;

            this.ColumnRootObject = generateFormModel.ColumnRootObject;

            this.ControlLayoutRoot = RootObject.None;

            if (generateFormModel.LabelPosition == LabelPosition.Left)
            {
                this.ControlLayoutRoot = RootObject.Grid;
            }

            if (generateFormModel.ColumnRootObject == RootObject.Grid)
            {
                this.ControlLayoutRoot = RootObject.None;
            }

            if (this.ViewModel.IncludeNextControlInRow)
            {
                this.ControlLayoutRoot = RootObject.Grid;
            }

            if (generateFormModel.ColumnRootObject == RootObject.TableView)
            {
                this.ControlLayoutRoot = RootObject.Grid;
            }

            // default these values to WPF & UWP & Silverlight
            var widthName  = "Width";
            var heightName = "Height";
            var horizontalAlignmentName = "HorizontalAlignment";
            var verticalAlignmentName   = "VerticalAlignment";

            if (generateFormModel.ProjectType == ProjectType.Xamarin)
            {
                widthName  = "WidthRequest";
                heightName = "HeightRequest";
                horizontalAlignmentName = "HorizontalOptions";
                verticalAlignmentName   = "VerticalOptions";

                if (!viewModel.Width.HasValue)
                {
                    switch (viewModel.ControlDefinition.ControlType)
                    {
                    case ControlType.XamarinButton:
                        this.HorizontalAlignmentText = $"{horizontalAlignmentName}=\"Start\" ";
                        break;

                    case ControlType.XamarinImage:
                        this.HorizontalAlignmentText = $"{horizontalAlignmentName}=\"Center\" ";
                        this.VerticalAlignmentText   = $"{verticalAlignmentName}=\"Center\" ";
                        break;

                    case ControlType.WpfButton:
                        this.HorizontalAlignmentText = $"{horizontalAlignmentName}=\"Left\" ";
                        this.VerticalAlignmentText   = $"{verticalAlignmentName}=\"Center\" ";
                        break;
                    }
                }
            }
            else if (generateFormModel.ProjectType == ProjectType.Wpf || generateFormModel.ProjectType == ProjectType.Silverlight)
            {
                if (!viewModel.Width.HasValue)
                {
                    switch (viewModel.ControlDefinition.ControlType)
                    {
                    case ControlType.WpfButton:
                    case ControlType.SilverlightButton:
                        this.HorizontalAlignmentText = $"{horizontalAlignmentName}=\"Left\" ";
                        this.VerticalAlignmentText   = $"{verticalAlignmentName}=\"Center\" ";
                        break;

                    case ControlType.WpfImage:
                    case ControlType.SilverlightImage:
                        this.HorizontalAlignmentText = $"{horizontalAlignmentName}=\"Center\" ";
                        this.VerticalAlignmentText   = $"{verticalAlignmentName}=\"Center\" ";
                        break;
                    }
                }
            }

            if (viewModel.Height.HasValue)
            {
                this.HeightText = $"{heightName}=\"{viewModel.Height.Value}\" ";
            }

            if (viewModel.Width.HasValue)
            {
                this.WidthText = $"{widthName}=\"{viewModel.Width.Value}\" ";
            }

            if (generateFormModel.AddNameToUIControls)
            {
                this.ControlNameText = $"x:Name=\"{viewModel.Name.Substring(0, 1).ToLower()}{viewModel.Name.Substring(1)}\" ";
            }

            if (viewModel.LabelWidth.HasValue)
            {
                this.LabelWidthText = $"{widthName}=\"{viewModel.LabelWidth.Value}\" ";
            }

            if (!String.IsNullOrWhiteSpace(viewModel.StringFormat))
            {
                this.StringFormatText = $", StringFormat='{viewModel.StringFormat}'";
            }

            this.TableSectionTitle = viewModel.TableSectionTitle;
        }