Exemple #1
0
        /*
         * Purely invalidating the layout as text is added to the TextBox will not cause it to expand.
         * If the TextBox is set to WordWrap and it is part of the layout it will refuse to Measure itself beyond its established width.
         * Even giving it infinite constraints will cause it to always set its DesiredSize to the same width but with a vertical growth.
         * The only way I was able to grow it was by setting layout renderers width explicitly to some value but then it just set its own Width to that Width which is not helpful.
         * Even vertically it would measure oddly in cases of rapid text changes.
         * Holding down the backspace key or enter key would cause the final result to be not quite right.
         * Both of these issues were fixed by just creating a static TextBox that is not part of the layout which let me just measure
         * the size of the text as it would fit into the TextBox unconstrained and then just return that Size from the GetDesiredSize call.
         * */
        Size GetCopyOfSize(FormsTextBox control, global::Windows.Foundation.Size constraint)
        {
            if (_copyOfTextBox == null)
            {
                _copyOfTextBox = CreateTextBox();

                // This causes the copy to be initially setup correctly.
                // I found that if the first measure of this copy occurs with Text then it will just keep defaulting to a measure with no text.
                _copyOfTextBox.Measure(_zeroSize);
            }

            _copyOfTextBox.Text        = control.Text;
            _copyOfTextBox.FontSize    = control.FontSize;
            _copyOfTextBox.FontFamily  = control.FontFamily;
            _copyOfTextBox.FontStretch = control.FontStretch;
            _copyOfTextBox.FontStyle   = control.FontStyle;
            _copyOfTextBox.FontWeight  = control.FontWeight;
            _copyOfTextBox.Margin      = control.Margin;
            _copyOfTextBox.Padding     = control.Padding;

            // have to reset the measure to zero before it will re-measure itself
            _copyOfTextBox.Measure(_zeroSize);
            _copyOfTextBox.Measure(constraint);

            Size result = new Size
                          (
                Math.Ceiling(_copyOfTextBox.DesiredSize.Width),
                Math.Ceiling(_copyOfTextBox.DesiredSize.Height)
                          );

            return(result);
        }
Exemple #2
0
 SizeRequest CalculateDesiredSizes(FormsTextBox control, global::Windows.Foundation.Size constraint, EditorAutoSizeOption sizeOption)
 {
     if (sizeOption == EditorAutoSizeOption.TextChanges)
     {
         Size result = GetCopyOfSize(control, constraint);
         control.Measure(constraint);
         return(new SizeRequest(result));
     }
     else
     {
         control.Measure(constraint);
         Size result = new Size(Math.Ceiling(control.DesiredSize.Width), Math.Ceiling(control.DesiredSize.Height));
         return(new SizeRequest(result));
     }
 }
Exemple #3
0
        public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            if (Children.Count == 0 || Control == null)
            {
                return(new SizeRequest());
            }

            var          constraint = new global::Windows.Foundation.Size(widthConstraint, heightConstraint);
            FormsTextBox child      = Control;

            child.Measure(constraint);
            var result = new Size(Math.Ceiling(child.DesiredSize.Width), Math.Ceiling(child.DesiredSize.Height));

            return(new SizeRequest(result));
        }