Bug 45608 - Xamarin Forms UWP - Entry Text Color during typing
Summary: Xamarin Forms UWP - Entry Text Color during typing
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-18 00:26 UTC by Maxime GUITTET
Modified: 2017-02-21 18:28 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Maxime GUITTET 2016-10-18 00:26:01 UTC
I got an issue about the [Entry Class](https://developer.xamarin.com/api/type/Xamarin.Forms.Entry/) of **Xamarin Forms**. The problem is, when I'm typing a text into this `Entry`, the text is black..

The thing is, the text of Entry, before it has been tapped, is `White` and the placeholder is `Gray`, however, when I'm typing, the text is black and not `White` like I would..

There is the Entry:

    public class CustomEntry : Entry
    {
        /// <summary>
        /// The HasBorder property.
        /// </summary>
        public static readonly BindableProperty HasBorderProperty =
            BindableProperty.Create(nameof(HasBorder), typeof(bool), typeof(CustomEntry), true);

        /// <summary>
        /// Assessor for the HasBorder property.
        /// </summary>
        public bool HasBorder
        {
            get { return (bool)GetValue(HasBorderProperty); }
            set { SetValue(HasBorderProperty, value); }
        }

        /// <summary>
        /// The XAlign property
        /// </summary>
        public static readonly BindableProperty XAlignProperty =
            BindableProperty.Create("XAlign", typeof(TextAlignment), typeof(CustomEntry), TextAlignment.Start);

        /// <summary>
        /// Gets or sets the X alignment of the text
        /// </summary>
        public TextAlignment XAlign
        {
            get { return (TextAlignment)GetValue(XAlignProperty); }
            set { SetValue(XAlignProperty, value); }
        }
    }

and then, the **Renderer** for the **UWP** platform:

    public class CustomEntryRenderer : EntryRenderer
    {
        /// <summary>
        /// Instance of our Custom control declared in the PCL part.
        /// </summary>
        CustomEntry customEntry;

        /// <summary>
        /// We override the OnElementChanged() event handler to get the desired instance. We also use it for updates.
        /// </summary>
        /// <param name="e">It contains either the NewElement or the OldElement.</param>
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                customEntry = e.NewElement as CustomEntry;

                if (customEntry != null)
                {
                    SetTextAlignment();
                    SetBorderPresence();
                    SetTextColor();
                }
            }
        }


        /// <summary>
        /// The on element property changed callback.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="PropertyChangedEventArgs"/>Instance containing the event data.</param>
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName == CustomEntry.XAlignProperty.PropertyName)
                SetTextAlignment();
            else if (e.PropertyName == CustomEntry.HasBorderProperty.PropertyName)
                SetBorderPresence();
            else if (e.PropertyName == CustomEntry.TextColorProperty.PropertyName)
                SetTextColor();
        }

        /// <summary>
        /// Sets the text alignment.
        /// </summary>
        /// <param name="view">The view.</param>
        private void SetTextAlignment()
        {
            switch (customEntry.XAlign)
            {
                case Xamarin.Forms.TextAlignment.Center:
                    Control.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
                    break;
                case Xamarin.Forms.TextAlignment.End:
                    Control.TextAlignment = Windows.UI.Xaml.TextAlignment.Right;
                    break;
                case Xamarin.Forms.TextAlignment.Start:
                    Control.TextAlignment = Windows.UI.Xaml.TextAlignment.Left;
                    break;
            }
        }

        /// <summary>
        /// Sets the border presence.
        /// </summary>
        private void SetBorderPresence()
        {
            if (!customEntry.HasBorder)
            {
                Control.BorderThickness = new Windows.UI.Xaml.Thickness();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        private void SetTextColor()
        {
            Debug.WriteLine("-- HEY --");
            Control.IsColorFontEnabled = true;
            Control.SelectionHighlightColor = new SolidColorBrush(Windows.UI.Color.FromArgb(126, 255, 255, 255));
            Control.Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(126, 255, 255, 255));
            Control.ForegroundFocusBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(126, 255, 255, 255));
            Control.PlaceholderForegroundBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(126, 255, 255, 255));
            Control.PlaceholderForegroundFocusBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(126, 255, 255, 255));
            Control.BackgroundFocusBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(126, 255, 255, 255));
            Debug.WriteLine("-- HEY --");
        }
    }

I tried everything but the Text is still black.. I didn't try for Android/iOS however..

I also though about the RequestedTheme but, it can be either dark or light, the typing text is still black.

Thank in advance for any help !
Comment 1 Paul DiPietro [MSFT] 2017-02-21 18:28:05 UTC
I believe this is related to 41054 should be fixed as of 2.3.4-pre1. If you're still experiencing issues with the foreground color, please reopen this.