When an Entry lost its focus, I want to change PlaceHolder color

EnricoRossiniEnricoRossini USMember ✭✭✭✭

Hi guys,
in my project I'm using Behaviour and Trigger to change the UI. In design point of view, when an Entry lost its Focus, it must change its color.

I don't know how I can implement that. Could you help me please?
Thank you in advance.

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    @EnricoRossini - There are various ways of doing this. I simply subclass Entry, and in my subclass override OnPropertyChanged as follows:

        protected override void OnPropertyChanged(string propertyName = null)
        {
            try
            {
                base.OnPropertyChanged(propertyName);
    
                if (propertyName == Entry.IsFocusedProperty.PropertyName)
                {
                    // Set colors here based on whether focused or unfocused
    
  • JulienRosenJulienRosen CAMember ✭✭✭✭

    i think you can use a DataTrigger bound against IsFocused

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I did an example of that in this other thread:
    https://forums.xamarin.com/discussion/comment/293719#Comment_293719

  • EnricoRossiniEnricoRossini USMember ✭✭✭✭

    Thanks guys!

    <Entry>
        <Entry.Triggers>
            <Trigger Property="Entry.IsFocused" Value="False" TargetType="Entry">
                <Setter Property="Entry.PlaceholderColor" Value="Red" />
            </Trigger>
        <Entry.Triggers>
    </Entry>
    

    Now a strange think happens. The FontSize change when it applies that. I don't understand why...

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @EnricoRossini said:
    Thanks guys!

    <Entry>
        <Entry.Triggers>
            <Trigger Property="Entry.IsFocused" Value="False" TargetType="Entry">
                <Setter Property="Entry.PlaceholderColor" Value="Red" />
            </Trigger>
        <Entry.Triggers>
    </Entry>
    

    Now a strange think happens. The FontSize change when it applies that. I don't understand why...

    We're not looking over your shoulder at your device. Screen shots showing before/after, focused/not would help us to know what you're seeing.

Sign In or Register to comment.