xamlxamarin.forms

How to set the disabled text colour of a xamarin forms entry field?


When an entry is disabled the text colour automatically changes to a greyish colour, and there seems to be no bindable property to override it. Ideally I'd like a fix that let's me set the text colour and doesn't rely on having to maintain a custom renderer.

My use case for this is - the entry is really acting as a label to hide a large amount of text truncated with an ellipsis, to save screen space. The full text will only be shown when the the user clicks an edit icon - the entry will be is hidden, and the entire text will be shown editable in a multi-line entry.

I would use a normal label but I need a placeholder to be displayed which labels don't support.

enter image description here

Setting the text colour doesn't help. Here's roughly my code now - IsVisible and IsEnabled and Text are all bound to viewmodel properties that I'm not showing here for clarity's sake.

 <Entry  IsEnabled="False" 
         IsVisible="True"
         Text="The disabled text..." 
         TextColor="White">

 </Entry>
 <Editor TextColor="White" IsVisible="False" Text="The disabled text in its full glory">
 </Editor>

Solution

  • A nice simple solution for this one: Instead of using IsEnabled use IsReadOnly - which doesn't affect the text colour.

    <Entry  IsReadOnly="True"
            Text="The disabled text..." 
            TextColor="White">
    </Entry>