Forum Xamarin.Forms

How to hide placeholder on Entry touch

amr_kamalamr_kamal Member ✭✭✭

I want to hide placeholder when user touch the entry and return normally if user touch another entry or Entry is empty I tried to use TapGesture for this but i don't have idea for this way how to make that ?
any another solution for this ?



  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    That's not normal or expected behavior. Are you sure you want to do that? It makes users twitchy when apps don't work like all the other apps on their device.

    Typically a placeholder exists until there is a value. When there is a genuine entry, then the placeholder will hide itself. If the value is totally cleared the placeholder will automatically return. That's the expected behavior.

    If you really want to remove the placeholder just set it to string.empty. But you can't hide it. You can clear it. If you want to re-show it at some point in the future you will have to store its current value before you clear it, then restore it to the saved value again.

  • amr_kamalamr_kamal Member ✭✭✭

    @ClintStLaurent sorry for wrong expression i mean to clear placeholder text when user touch the entry is it possible ?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Yes. As I described above how you could do it. Set the placeholder to string.empty
    Just be aware that when you choose to do non-standard things you will have to be responsible for all of the custom behavior from start to end. Its not going to automatically re-populate when the Entry looses focus- you have to code that too.

  • amr_kamalamr_kamal Member ✭✭✭

    String.empty will make placeholder empty if i touch it but when i let it it should return to the normal case
    for example if you touch Email Entry Email word should be hidden if you touch another entry Email entry placeholder should appear again

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Now you're just repeating what I already said.
    There is no 'hide' of the placeholder.

    if you touch Email Entry Email word should be hidden

    No. That's not what should happen. That's what you're choosing you want to have happen DIFFERENTLY than the expected behavior. The Entry already does what should happen and what is expected on every mobile platform. The people that make the infrastructure already saw to that.

    What you're describing is custom behavior that you want. And thus you are responsible for everything that goes along with that from start to finish. You have to store the old placeholder when you clear it. And you have to reset the placeholder to that stored value when you want to bring it back.

  • amr_kamalamr_kamal Member ✭✭✭

    @ClintStLaurent thank you for your help so now what's the event i should fire for entry touchable ?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    You probably want to work off off FocusChanged.
    You really don't care if it was touched so much as if it gets focus, either because it was touched, or some code set it to the focused control.

  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    I recommend a trigger. Set it up on IsFocused == false, placeholder = value, or IsFocused == true, placeholder = string.Empty. Whichever works for you.

Sign In or Register to comment.