示例#1
0
 public static void UpdateHorizontalTextAlignment(this MauiTextBox textBox, IEntry entry)
 {
     // We don't have a FlowDirection yet, so there's nothing to pass in here.
     // TODO: Update this when FlowDirection is available
     // (or update the extension to take an ILabel instead of an alignment and work it out from there)
     textBox.TextAlignment = entry.HorizontalTextAlignment.ToNative(true);
 }
示例#2
0
 public static void UpdateFont(this MauiTextBox nativeControl, Font font, IFontManager fontManager)
 {
     nativeControl.FontSize   = fontManager.GetFontSize(font);
     nativeControl.FontFamily = fontManager.GetFontFamily(font);
     nativeControl.FontStyle  = font.ToFontStyle();
     nativeControl.FontWeight = font.ToFontWeight();
 }
示例#3
0
        public static void UpdatePlaceholderColor(this MauiTextBox textBox, IPlaceholder placeholder, Brush?defaultPlaceholderColorBrush, Brush?defaultPlaceholderColorFocusBrush)
        {
            Color placeholderColor = placeholder.PlaceholderColor;

            BrushHelpers.UpdateColor(placeholderColor, ref defaultPlaceholderColorBrush,
                                     () => textBox.PlaceholderForegroundBrush, brush => textBox.PlaceholderForegroundBrush = brush);

            BrushHelpers.UpdateColor(placeholderColor, ref defaultPlaceholderColorFocusBrush,
                                     () => textBox.PlaceholderForegroundFocusBrush, brush => textBox.PlaceholderForegroundFocusBrush = brush);
        }
示例#4
0
        public static void UpdateMaxLength(this MauiTextBox textBox, IEditor editor)
        {
            textBox.MaxLength = editor.MaxLength;

            var currentControlText = textBox.Text;

            if (currentControlText.Length > editor.MaxLength)
            {
                textBox.Text = currentControlText.Substring(0, editor.MaxLength);
            }
        }
示例#5
0
        public static void UpdateTextColor(this MauiTextBox textBox, ITextStyle textStyle)
        {
            if (textStyle.TextColor == null)
            {
                return;
            }

            var brush = textStyle.TextColor.ToNative();

            textBox.Foreground           = brush;
            textBox.ForegroundFocusBrush = brush;
        }
示例#6
0
        public static void UpdateText(this MauiTextBox nativeControl, IEditor editor)
        {
            string newText = editor.Text;

            if (nativeControl.Text == newText)
            {
                return;
            }

            nativeControl.Text = newText;

            if (!string.IsNullOrEmpty(nativeControl.Text))
            {
                nativeControl.SelectionStart = nativeControl.Text.Length;
            }
        }
示例#7
0
        internal static void UpdateInputScope(this MauiTextBox textBox, ITextInput textInput)
        {
            if (textInput.Keyboard is CustomKeyboard custom)
            {
                textBox.IsTextPredictionEnabled = (custom.Flags & KeyboardFlags.Suggestions) != 0;
                textBox.IsSpellCheckEnabled     = (custom.Flags & KeyboardFlags.Spellcheck) != 0;
            }
            else
            {
                textBox.IsTextPredictionEnabled = textInput.IsTextPredictionEnabled;

                // TODO: Update IsSpellCheckEnabled
            }

            textBox.InputScope = textInput.Keyboard.ToInputScope();
        }
示例#8
0
        public static void UpdateMaxLength(this MauiTextBox textBox, IEntry entry)
        {
            var maxLength = entry.MaxLength;

            if (maxLength == -1)
            {
                maxLength = int.MaxValue;
            }

            textBox.MaxLength = maxLength;

            var currentControlText = textBox.Text;

            if (currentControlText.Length > maxLength)
            {
                textBox.Text = currentControlText.Substring(0, maxLength);
            }
        }
示例#9
0
        public static Windows.Foundation.Size GetCopyOfSize(MauiTextBox control, Windows.Foundation.Size constraint)
        {
            if (_copyOfTextBox == null)
            {
                _copyOfTextBox = new MauiTextBox
                {
                    Style = Microsoft.UI.Xaml.Application.Current.Resources["MauiTextBoxStyle"] as Microsoft.UI.Xaml.Style
                };

                // 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.MinHeight     = control.MinHeight;
            _copyOfTextBox.MaxHeight     = control.MaxHeight;
            _copyOfTextBox.MinWidth      = control.MinWidth;
            _copyOfTextBox.MaxWidth      = control.MaxWidth;
            _copyOfTextBox.TextWrapping  = control.TextWrapping;
            _copyOfTextBox.AcceptsReturn = control.AcceptsReturn;
            _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);

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

            return(result);
        }
示例#10
0
 public static void UpdatePlaceholder(this MauiTextBox textBox, IEntry entry)
 {
     textBox.PlaceholderText = entry.Placeholder ?? string.Empty;
 }
示例#11
0
 public static void UpdatePlaceholder(this MauiTextBox textBox, IEditor editor)
 {
     textBox.PlaceholderText = editor.Placeholder ?? string.Empty;
 }
示例#12
0
 public static void UpdateClearButtonVisibility(this MauiTextBox textBox, IEntry entry)
 {
     textBox.ClearButtonVisible = entry.ClearButtonVisibility == ClearButtonVisibility.WhileEditing;
 }
示例#13
0
 public static void UpdateKeyboard(this MauiTextBox textBox, IEditor editor)
 {
     textBox.UpdateInputScope(editor);
 }
示例#14
0
 public static void UpdateIsReadOnly(this MauiTextBox textBox, IEntry entry)
 {
     textBox.IsReadOnly = entry.IsReadOnly;
 }
示例#15
0
 public static void UpdateText(this MauiTextBox textBox, IEntry entry)
 {
     textBox.Text = entry.Text;
 }
示例#16
0
 public static void UpdateVerticalTextAlignment(this MauiTextBox textBox, IEntry entry)
 {
     textBox.VerticalAlignment = entry.VerticalTextAlignment.ToNativeVerticalAlignment();
 }
示例#17
0
 public static void UpdateIsPassword(this MauiTextBox textBox, IEntry entry)
 {
     textBox.IsPassword = entry.IsPassword;
 }
示例#18
0
 public static void UpdateFont(this MauiTextBox nativeControl, IText text, IFontManager fontManager) =>
 nativeControl.UpdateFont(text.Font, fontManager);
示例#19
0
 public static void UpdateCharacterSpacing(this MauiTextBox textBox, IEntry entry)
 {
     textBox.CharacterSpacing = entry.CharacterSpacing.ToEm();
 }
示例#20
0
 public static void UpdateIsReadOnly(this MauiTextBox textBox, IEditor editor)
 {
     textBox.IsReadOnly = editor.IsReadOnly;
 }
示例#21
0
 public static void UpdateReturnType(this MauiTextBox textBox, IEntry entry)
 {
     textBox.InputScope = entry.ReturnType.ToNative();
 }
示例#22
0
 public static void UpdateCharacterSpacing(this MauiTextBox textBox, ITextStyle textStyle)
 {
     textBox.CharacterSpacing = textStyle.CharacterSpacing.ToEm();
 }
示例#23
0
 public static void UpdateIsTextPredictionEnabled(this MauiTextBox textBox, IEditor editor)
 {
     textBox.UpdateInputScope(editor);
 }