Ejemplo n.º 1
0
        /// <summary>
        /// Builds complete view of field. Puts label, active element and validation element togetger in specified order.
        /// </summary>
        /// <param name="field">field of which view is created</param>
        /// <param name="skin">in this case defines dimensions of field parts</param>
        /// <returns>complete graphical representation of field</returns>
        private FrameworkElement buildCompleteView(AFField field, Skin skin)
        {
            StackPanel fullLayout = new StackPanel();
            //fullLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

            Layout layout = field.getFieldInfo().getLayout();
            //set orientation of label and field itself
            if (layout.getLayoutOrientation() != null)
            {
                if (layout.getLayoutOrientation().Equals(LayoutOrientation.AXISY))
                {
                    fullLayout.Orientation = Orientation.Horizontal;
                }
                else if (layout.getLayoutOrientation().Equals(LayoutOrientation.AXISX))
                {
                    fullLayout.Orientation = Orientation.Vertical;
                }
            }
            else {
                fullLayout.Orientation = Orientation.Vertical; //default
            }

            //set label and field view layout params
            if (field.getLabel() != null)
            {
                if (skin.getLabelWidth() >= 0)
                {
                    field.getLabel().Width = skin.getLabelWidth();
                }
                else
                {
                    field.getLabel().HorizontalAlignment = skin.getLabelHorizontalAlignment();
                }
                if(skin.getLabelHeight() >= 0) { 
                    field.getLabel().Height = skin.getLabelHeight();
                }
                else
                {
                    field.getLabel().VerticalAlignment = skin.getLabelVerticalAlignment();
                }
            }
            field.getFieldView().Width = skin.getInputWidth();
            field.getFieldView().VerticalAlignment = VerticalAlignment.Top;

            //LABEL BEFORE
            if (field.getLabel() != null && layout.getLabelPosition() != null && !layout.getLabelPosition().Equals(LabelPosition.NONE))
            {
                if (layout.getLabelPosition().Equals(LabelPosition.BEFORE))
                {
                    fullLayout.Children.Add(field.getLabel());
                }
            }
            else if (field.getLabel() != null && layout.getLabelPosition() == null)
            {
                fullLayout.Children.Add(field.getLabel()); //default is before
            }

            if (field.getFieldView() != null)
            {
                fullLayout.Children.Add(field.getFieldView());
            }
            //LABEL AFTER
            if (field.getLabel() != null && layout.getLabelPosition() != null && !layout.getLabelPosition().Equals(LabelPosition.NONE))
            {
                if (layout.getLabelPosition().Equals(LabelPosition.AFTER))
                {
                    fullLayout.Children.Add(field.getLabel());
                }
            }

            //add errorview on the top of field
            StackPanel fullLayoutWithErrors = new StackPanel();
            fullLayoutWithErrors.HorizontalAlignment = HorizontalAlignment.Stretch;
            fullLayoutWithErrors.VerticalAlignment = VerticalAlignment.Top;
            //fullLayoutWithErrors.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            fullLayoutWithErrors.Margin = new Thickness(0, 0, 10, 10);
            fullLayoutWithErrors.Orientation = Orientation.Vertical;
            fullLayoutWithErrors.Children.Add(field.getErrorView());
            fullLayoutWithErrors.Children.Add(fullLayout);
            return fullLayoutWithErrors;
        }