Exemplo n.º 1
0
        void OnControlLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            _queryTextBox = Control.GetFirstDescendant <FormsTextBox>();
            _cancelButton = _queryTextBox?.GetFirstDescendant <FormsCancelButton>();

            if (_cancelButton != null)
            {
                // The Cancel button's content won't be loaded right away (because the default Visibility is Collapsed)
                // So we need to wait until it's ready, then force an update of the button color
                _cancelButton.ReadyChanged += (o, args) => UpdateCancelButtonColor();
            }

            UpdateHorizontalTextAlignment();
            UpdateVerticalTextAlignment();
            UpdateTextColor();
            UpdatePlaceholderColor();
            UpdateBackgroundColor();
            UpdateBackground();
            UpdateIsSpellCheckEnabled();
            UpdateInputScope();
            UpdateMaxLength();
            SetAutomationId(Element.AutomationId);

            // If the Forms VisualStateManager is in play or the user wants to disable the Forms legacy
            // color stuff, then the underlying textbox should just use the Forms VSM states
            if (_queryTextBox != null)
            {
                _queryTextBox.UseFormsVsm = Element.HasVisualStateGroups() ||
                                            !Element.OnThisPlatform().GetIsLegacyColorModeEnabled();
            }
        }
Exemplo n.º 2
0
        public static Size GetCopyOfSize(FormsTextBox control, Windows.Foundation.Size constraint)
        {
            if (_copyOfTextBox == null)
            {
                _copyOfTextBox = new FormsTextBox
                {
                    Style = Microsoft.UI.Xaml.Application.Current.Resources["FormsTextBoxStyle"] 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 Size
                         (
                Math.Ceiling(_copyOfTextBox.DesiredSize.Width),
                Math.Ceiling(_copyOfTextBox.DesiredSize.Height)
                         );

            return(result);
        }